var
form:Tform2;
procedure
TForm1
.
Button1Click(Sender: TObject);
begin
if
form=
nil
then
//也可写成if not Assigned(form) then
begin
form:=Tform2
.
Create(application);
end
;
else
begin
if
form
.
WindowState=wsMinimized
then
begin
ShowWindow(form
.
Handle,SW_SHOWNORMAL);
if
(
not
form
.
Visible )
then
//打开,但不可见
begin
form
.
Visible :=
True
;
form
.
BringToFront;
form
.
SetFocus ;
Exit;
end
;
end
;
end
;
form
.
Show;
end
;