Jump to content
Mike Warren

Hide Main Form on Start

Recommended Posts

In the past all I needed to do was add Application.ShowMainForm := False, but FMX does not have ShowMainForm.

 

Setting the main form's Visible property to False, either at design time, or in Form.Create does nothing, and adding MyForm.Visible := False to the application anywhere before Application.Run causes an A/V.

 

I need this to work on Windows and Mac, so a WinAPI solution is not suitable.

 

Does anyone have a suggestion?

 

Share this post


Link to post

Thanks for the reply, Nigel.

 

Unfortunately, the form flashes up briefly at the default position and size before being hidden.

 

Below is something I just thought of. It seems to work fine on Windows. I'm not able to test on Mac at the moment.

 

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    StartLeft: Integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.FormCreate(Sender: TObject);
begin
  StartLeft := Left;
  Left := MaxInt;
  Timer1.Interval := 4000;
  Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  Left := StartLeft;
end;

end.

 

Share this post


Link to post
57 minutes ago, Nigel Thomas said:

Actually, that StackOverflow thread looks like it might contain the answer in the second reply.

 

Overriding the CanShow method seems to stop the flash.

 

function TForm1.CanShow: Boolean;
begin
  Result := not Timer1.Enabled;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  Left := 500;
  Top := 200;
  Visible := True;
end;

 

Edited by Mike Warren

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×