Delphi xe3 Mainform hide

I am trying to run an application with hiden main form, but no luck. It compiles and that's it, but when I run it, I get a runtime error. When I use the timer and set it to 1 millisecond and then call Application.MainForm.Hide it hides, but it blinks, I do not want this to happen

 program Project1; uses FMX.Forms, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.MainForm.Visible := false; Form1.Visible:=false; Application.Run; end. 
+4
source share
2 answers

In the FireMonkey application, forms are automatically created (created), and the MainForm property MainForm assigned in the Application.Run method. Thus, the access violation is caused by the fact that the MainForm property and form1 are nil.

To access these properties, you must first run the RealCreateForms method

 begin Application.Initialize; Application.CreateForm(TForm2, Form1); Application.RealCreateForms; //Application.MainForm.Left:=-Application.MainForm.Width; Application.MainForm.Visible:=False; Application.Run; end. 
+6
source

A much simpler method is to override CanShow:

 type TfrmMain = class(TForm) public function CanShow: Boolean; override; end; ... function TfrmMain.CanShow: Boolean; begin Result := False; // Or return True when it OK to show end; 
0
source

All Articles