System Delphi

Title: Only one instance of a specific MDIChild window
Question: A function to check if an instance of a specific MDIChild Window already exists.
Answer:
The following function was tested with Delphi 6 Enterprise Edition on Windows 2000....but it should work just fine with Delphi 4 and up under any Windows version.
The function checks if an instance of a specific MDIChild window already exists. If it exists the function returns the index number of the MDIChild window else it returns -1. Depending on the return value of the function you can either create the MDIChild window or bring it to the front so the user can see it. The function requires on parameter, this is the name of the form you wish to create/show.
function TMainMenu.checkMDIChildren(Name: String): Integer;
var
i : Integer;
begin
//Check it the MDIChild window you want to create already exists.
Result := -1;
i := 0;
for i:=0 to Self.MDIChildCount - 1 do
begin
if (Self.MDIChildren[i].Name = Name) then
begin
Result := i;
Exit;
end;
end;
end;
You can call this function like this:
procedure TMainMenu.ToolBarButtonClick(Sender: TObject);
var
check : Integer;
begin
check := checkMDIChildren('Form2');
if (check = -1) then
TForm2.create(Self)
else
Self.MDIChildren[check].BringToFront;
end;
end;