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.
Asked
Active
Viewed 793 times
-2
-
4Have you tried creating and showing the dialog in the main form's OnShow event? You should explain what you have tried and why it hasn't worked in your question. – Andy_D Dec 13 '13 at 14:21
-
Seems a duplicate of this: http://stackoverflow.com/questions/6203090/how-can-i-make-a-a-dialog-box-happen-directly-after-my-apps-main-form-is-visibl?rq=1 – Giacomo Degli Esposti Dec 13 '13 at 14:31
-
Sure. I've tried in OnShow, OnActivate and even OnCreate with no results. – Avrob Dec 13 '13 at 15:14
-
4You have accepted an answer that demonstrates how to display a *modal* form. Nowhere in your question you have mentioned that this would be what you want. Please take a minute while asking a question to specify your requirements clearly. That will save you and other people from wasting time. – Sertac Akyuz Dec 13 '13 at 15:19
2 Answers
1
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;

David Heffernan
- 601,492
- 42
- 1,072
- 1,490
0
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.

Hugh Jones
- 2,706
- 19
- 30