Question

We have Delphi XE MDI project. We need to open a Dialog form (form with with bsDialog property) at the startup of the application just after the MDI main form has been created and showed.

Was it helpful?

Solution 2

You can do this

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Form1.Show; // iff really necessary
  with TForm2.Create(nil) do try
    ShowModal;
  finally
    Free;
  end;
  Application.Run;
end.

OTHER TIPS

You can add something to your form's OnShow event, but the dialog will show before the main form is actually visible. So, you need to delay the showing of the dialog until the main form is actually visible.

I'm sure there are other ways to do this, but I add a handler to TApplication.OnIdle, and show the dialog there. Obviously you'd need to use a boolean flag in the main form to make sure that the dialog was only ever shown once. And it's generally cleaner to use TApplicationEvents to work around Delphi's lack of multi-cast events.

procedure TMainForm.ApplicationIdle(Sender: TObject; var Done: Boolean);
begin
  if not FStartupCalled then begin
    FStartupCalled := True;//FStartupCalled is a member field of TMainForm
    DoApplicationStartup;//this would show your dialog
  end;
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top