Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-11

TForm.OnCreate and Application.MainForm.Caption

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

John Landmesser

Error on Lazarus Windows(!):
"Lazarus 0.9.31 r33456 FPC 2.5.1 i386-win32-win32/win64"

procedure TForm1.FormCreate(Sender: TObject);
begin
  // next line produces error
  Application.MainForm.Caption:= Application.Title;
  // next line does NOT produce an error
  Form1.Caption:= Application.Title;
end;
//BUT(!!),you get no error with the OnShow event
procedure TForm1.FormOnShow(Sender: TObject);
begin
  // next line does NOT produces  error
  Application.MainForm.Caption:= Application.Title;
end;

What is the reason for that ?

John

Reply by email

Michael Fuchs
to John Landmesser
John Landmesser wrote 7 lines
procedure TForm1.FormCreate(Sender: TObject); begin // next line produces error Application.MainForm.Caption:= Application.Title; // next line does NOT produce an error Form1.Caption:= Application.Title; end;

In FormCreate, the Form1 is not assigned to Application.MainForm. This is done after the complete creation process.

Show quoted text 7 lines
//BUT(!!),you get no error with the OnShow event procedure TForm1.FormOnShow(Sender: TObject); begin // next line does NOT produces error Application.MainForm.Caption:= Application.Title; end;

- the creation process is done
- then Form1 is assigned to Application.MainForm
- then Form1.Show is called

Please take a look into TApplication.CreateForm for further informations.

hth
Michael

Reply by email