Article B0003 Delphi
Iterate through MDI-forms

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 in the following manner:

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;