Problem with alignment of controls in dynamically created frame

My program uses dynamically created frames, and sometimes I get a message that their controls are not aligned correctly.

I use my own container control, inherited from TPanel, but the same problem can be found when using GridPanel.

Here is the test source that reproduces the problem (with compiled exe).

Key code snippets:

in the main form:

//creating Frame from the main form
procedure TForm1.FormCreate(Sender: TObject);
begin
  f := TFrame2.Create(Self);
  f.Parent := Self;
end;

in frame:

//constructor of the Frame
constructor TFrame2.Create(AOwner: TComponent);
begin
  inherited;
  Edit1.Clear;// the problem appears
end;

The frame and all its controls are aligned and must have the width of the main form, but Edit1they ComboBox1do not visually align until you manually resize the form (Submission WM_SIZEdoes not affect).

Edit1.Clear, . , , . ComboBox1.Items.Add('') ..

GridPanel Panel, .

test2 @quasoft, - , combobox , , .

+4
1

:

Text TEdit Clear - , Edit1.Clear Edit1.Text := ''.

, Delphi , , ().

, , Parent.

procedure TForm1.FormCreate(Sender: TObject);
begin
  f := TFrame2.Create(Self);    // <--- Your text edit is cleared inside
  f.Parent := Self;             // <--- Your frame is attached to the form here
end;

TGridPanel , .

Text , , :

Controls.pas:

...
procedure TControl.SetTextBuf(Buffer: PChar);
begin
  Perform(WM_SETTEXT, 0, Longint(Buffer));
  Perform(CM_TEXTCHANGED, 0, 0);
end;

procedure TControl.SetText(const Value: TCaption);
begin
  if GetText <> Value then SetTextBuf(PChar(Value));
end;
...

, , Parent , .

Clear , , :

StdCtrls.pas:

...
procedure TCustomEdit.Clear;
begin
  SetWindowText(Handle, '');
end;
...

, , .

Init Parent:

:

procedure TFrame2.Init;
begin
  Edit1.Clear;
  ComboBox1.Items.Add('Foo Bar');
end;

:

procedure TForm1.FormCreate(Sender: TObject);
begin
  f := TFrame2.Create(Self);
  f.Parent := Self;             // <--- Your frame is attached to the form here
  f.Init;                       // <--- Calls initialization code of frame
end;
+3

Source: https://habr.com/ru/post/1668103/


All Articles