Reputation: 55
I have been trying to start my application with hiden main form, but no luck. It
compiles and everything, but when I run it I get runtime error. When I use timer and set it to 1 millisecond and then call Application.MainForm.Hide
it hides but it flashes i dont want that 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.
Upvotes: 4
Views: 2178
Reputation: 3602
Much easier method - override CanShow:
type
TfrmMain = class(TForm)
public
function CanShow: Boolean; override;
end;
...
function TfrmMain.CanShow: Boolean;
begin
Result := False; // Or return True when it's OK to show
end;
Upvotes: 0
Reputation: 136391
In a FireMonkey application the Auto-created forms (are created) and the MainForm
property is assigned in the Application.Run
method. So the access violation is caused because the MainForm
property and form1
variable is nil.
In order to access such properties you must execute the RealCreateForms
method first
begin
Application.Initialize;
Application.CreateForm(TForm2, Form1);
Application.RealCreateForms;
//Application.MainForm.Left:=-Application.MainForm.Width;
Application.MainForm.Visible:=False;
Application.Run;
end.
Upvotes: 6