Jump to content
bazzer747

Form 'appears' before it should

Recommended Posts

Hi,

I have an application with a main form - fSloggs - with a button that opens another form - fMatchResult - with:

 

fMatchResult.Show;

 

However, this other form pops up immediately after the FormCreate of the fSloggs form and before the FormActivate of the form.

 

The source for the executable looks like this:


 

program PGCSloggs;

uses
  Vcl.Forms,
  uSlogg in 'uSlogg.pas' {fSloggs},
  Vcl.Themes,
  Vcl.Styles,
  dm in 'dm.pas' {dm1: TDataModule},
  uMatchResult in 'uMatchResult.pas' {fMatchResult},
{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(Tdm1, dm1);
  Application.CreateForm(TfSloggs, fSloggs);
  Application.CreateForm(TfMatchResult, fMatchResult);
  Application.Run;
end.

 

I can't see any reason why the fMatchResult form should pop up without the button being pressed. Also, not sure what the 'Application.MainFormOnTaskBar:= True' is about.

 

Any thoughts would be appreciated.

Edited by Sherlock
Please consider using the code tags for better readability

Share this post


Link to post

Check if fMatchResult has its Visible = True in the designer and switch it off to fix the issue.

Share this post


Link to post

Fixed!!! How simple .... How did this get set to visible = true anyway, I wonder.

 

Many thanks ... I'd trawled though the Properties but that never occurred to me.

Share this post


Link to post

It would be more correct to create the form only at the moment of need.
Of course, this also depends on the logic of the program.

Share this post


Link to post

Personally, I'd rather not create the form until it's needed because apparently that makes it load faster, but I'm not an expert, LOL.

  • Like 1

Share this post


Link to post

HI,

Thanks Stano and Haley, you are both right (as was Uwe). 

I was auto-creating the form at startup. I've shifted it to the right in Project Options so it only gets created when the button is first pressed.

 

The form isn't too big so loading times aren't an issue, but probably good practice.

 

Thanks to all.

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

×