Author: Tomas Rutkauskas
How can I prevent to open a MDIChild if it is already open? When I select the same
option on the menu, the first code executes again and I get two forms.
Answer:
1 2 procedure TformMain.doDisplayCustomerLookupGrid(Sender: TObject);
3 var4 MyChildFormName: string;
5 MyChild: TformCustGrid;
6 I: Integer;
7 begin8 MyChildFormName := 'Customer Lookup';
9 { If the child form already exists, make it active }10 with formMain do11 for I := 0 to MDIChildCount - 1 do12 begin13 if MDIChildren[I].Caption = MyChildFormName then14 begin15 MDIChildren[I].BringToFront;
16 exit;
17 end;
18 end;
19 { If the child form does not exist, create it }20 MyChild := TformCustGrid.Create(Application);
21 MyChild.Caption := MyChildFormName;
22 end;