Jump to content
Mowafaq

Showing secondary form from the main form OnShow event

Recommended Posts

Hello everyone,

 

I am having trouble showing a secondary form from the main form OnShow event for (only) the Android platform. The Show call does nothing at all except for a short delay. The main form stays active and functions correctly.

 

The program runs nicely on Windows.

 

This second form is StayOnTop and position=Designed with the same size as the main form.

 

Thanks in advance for any help I can get.

 

procedure TMainForm.FormShow(Sender: TObject);
begin
    SetScreensLang;
    if MustSignIn then begin
        TabControl1.ActiveTab := PersonalTabItem;
        SignForm.Show;
        end
    else begin
        CheckAlerts;
        TabControl1.ActiveTab := AlertsTabItem;
        AlertsTabItemClick(nil);
    end;
end;
 

Share this post


Link to post

Found out a work-around. Hiding the main form before the call to Show then setting MainForm.Visible := True after the secondary form closed did the trick.

 

Never mind.

Share this post


Link to post

Another option I can think of is to delay showing the secondary Form until after the Main Form is done fully showing itself.  For instance, via TThread.ForceQueue(), eg:

procedure TMainForm.FormShow(Sender: TObject);
begin
  SetScreensLang;
  if MustSignIn then begin
    TabControl1.ActiveTab := PersonalTabItem;
    TThread.ForceQueue(SignForm.Show); // <--
  end
  else begin
    CheckAlerts;
    TabControl1.ActiveTab := AlertsTabItem;
    AlertsTabItemClick(nil);
  end;
end;

 

  • Like 1

Share this post


Link to post
12 hours ago, Remy Lebeau said:

Another option I can think of is to delay showing the secondary Form until after the Main Form is done fully showing itself.  For instance, via TThread.ForceQueue(), eg:


procedure TMainForm.FormShow(Sender: TObject);
begin
  SetScreensLang;
  if MustSignIn then begin
    TabControl1.ActiveTab := PersonalTabItem;
    TThread.ForceQueue( nil, procedure begin SignForm.Show; end ); // <-- Inside an anon. procedure
  end
  else begin
    CheckAlerts;
    TabControl1.ActiveTab := AlertsTabItem;
    AlertsTabItemClick(nil);
  end;
end;

 

@Remy LebeauI think you mean like above, inside an anonymous method.

 

Edited by Rollo62

Share this post


Link to post
13 hours ago, Rollo62 said:

@Remy LebeauI think you mean like above, inside an anonymous method.

No, I meant what I posted.  An anonymous procedure is not necessary.  TThread.ForceQueue() accepts both standard method closures and anonymous procedures as input, same as TThread.Synchronize() and TThread.Queue() do:

type
  TThreadMethod = procedure of object;
  TThreadProcedure = reference to procedure

class procedure ForceQueue(const AThread: TThread; const AMethod: TThreadMethod; ADelay: Integer = 0); overload; static;
class procedure ForceQueue(const AThread: TThread; const AThreadProc: TThreadProcedure; ADelay: Integer = 0); overload; static;

What I had left off by accident in my example was just the nil TThread parameter:

TThread.ForceQueue(nil, SignForm.Show);

 

Edited by Remy Lebeau
  • Like 1

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

×