1.例程如下:
type
TMyMDIChild = class(TForm)
...
procedure FormCreate(...);
procedure FormClose(...);
public
class function InstanceCount: Integer;
end;
implementation
const
InstCount: Integer = 0;
procedure TMyMDIChild.FormCreate(...);
begin
Inc(InstCount);
...
end;
procedure TMyMDIChild.FormClose(...);
begin
Dec(InstCount);
...
end;
class function TMyMDIChild.InstanceCount: Integer;
begin
Result := InstCount;
end;
////////////////////////////////////////
type
TMainForm = class(TForm)
...
public
function CreateMDIChild: TMyMDIChild;
...
end;
....
function TMainForm.CreateMDIChild: TMyMDIChild;
begin
if TMyMDIChild.InstanceCount > 0 then
ShowMessage('MDI Child has opened!')
else Result := TMyMDIChild(Application);
end;
2。MDIChild.BringToFront