/ Universal sub-form switch
Procedure OpenForm (FormClass: TFormClass; VAR AFORM;
Aowner: tComponent = NIL);
VAR
i: integer;
Child: TForm;
Begin
For i: = 0 TO Screen.formcount -1 DO
IF screen.forms [i] .CLASSTYPE = FormClass THEN
Begin
Child: = Screen.Forms [i];
If child.windowstate = wsminimized then
Child.windowState: = WSNORMAL;
Child.bringtofront;
Child.setfocus;
TFORM (AFORM): = CHILD;
EXIT;
END;
Child: = TFORM (FormClass.newinstance);
TFORM (AFORM): = CHILD;
IF NOT Assigned (Aowner) THEN AOWNER: = Application;
Child.create (aowner);
END;
Use: OpenForm (TFORM1, FORM1);