Everyone know tell me why Form.show is called before that Form.create if property Form.visible = true.
I tested in Delphi XE7 and Delphi 10 Seattle (Fmx form compiled for windows)
Ex:
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
begin
//break point here is called before if form.visible = false
i := 0;
end;
procedure TForm1.FormShow(Sender: TObject);
var
i : integer;
begin
//break point here is called before if form.visible = true
i := 0;
end;
If the main form is not set to be visible in the designer then the call to CreateMainForm()
will force the form to be visible after construction is complete (and therefore after OnCreate
has fired).
procedure TApplication.CreateMainForm;
var
I: Integer;
begin
if FMainForm = nil then
begin
// here creating form...
end;
if FMainForm <> nil then
FMainForm.Visible := True; //** force visible here
end;
Otherwise, the form's Visible
property is set during the call to TCommonCustomForm.Loaded()
, which is called by the DFM streaming system during form construction, and thus triggers OnShow
when the form becomes visible. OnCreate
is not called until after construction is complete, after the DFM is streamed.
The bottom line is that you should not be making assumptions about when these events will be executed. If you need to control the order in which things happen, you'll need to do it explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With