My program uses dynamically created frames and sometimes I get an issue that their controls are improperly aligned.
I use my own container control inherited from TPanel
, but the same problem can be found when using the GridPanel
as well.
Here is the source of a test program that reproduces the problem (with compiled exe).
The 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 the 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 Edit1
and ComboBox1
are visually not aligned until you resize the form manually (Sending WM_SIZE
has no effect).
But if you comment the Edit1.Clear
line everything will work fine from the program start. This code is not specific for the error and you can enter here e.g. ComboBox1.Items.Add('')
etc.
If the frame is created statically or the GridPanel
is changed to Panel
the problem disappears.
I have made a new test2 version thanks to @quasoft, it works better - now the controls are horizontally aligned proper but vertically combobox is not in the right place that can be seen by changing the form size.
Edit1.Clear
withEdit1.Text := ''
it works as you would expect – quasoftEdit1.Clear;
– IlyesWindowHandle
in theTFrame2.Create
in both cases (static and dynamic). You might want to init your "Handle dependent" controls in the FrameCreateWnd
handler, where you know the controls have valid window handle. (I can't test this right now). – kobik