Mirror

How to create only one instance of a MDI child form (Views: 101)


Problem/Question/Abstract:

I want the form only to appear once on the user's desktop regardless of whether it has focus or not.

Answer:

procedure TfmMain.fmAboutClick(Sender: TObject);
begin
  if not (ActiveMDIChild is TfmAboutBox) then
    TfmAboutBox.Create(Application);
end;

procedure TfmMain.fmAboutClick(Sender: TObject);
var
  myAbout: TfmAboutBox;
  i: integer;
begin
  for i := 0 to Screen.FormCount - 1 do
    if (Screen.Forms[i] is TfmAboutBox) then
      myAbout := Screen.Forms[i] as TfmAboutBox; {Form Exists}
  if myAbout = nil then {didn't find it so create it...}
    myAbout = TfmAboutBox.Create(Application);
  myAbout.Show;
end;

<< Back to main page