若窗体大打再点的时候不再创建(100分)

  • 主题发起人 主题发起人 rgxrose
  • 开始时间 开始时间
R

rgxrose

Unregistered / Unconfirmed
GUEST, unregistred user!
我的主窗体调所子窗体是在每个子窗体的最后写上
initialization
registerClass(TggyhF);--括号内为子窗体的名称
finalization
unregisterClass(TggyhF);
可是我每点一个都创建一个子窗体,若子窗体已打开,再点都只有一个窗体而不是多个窗体。
 
加一个判断:
initialization
if TggyhF = nil then
registerClass(TggyhF);
 
function OpenForm(
const AClassName : string;
const AOwner : TComponent=nil
):TForm;
//根据窗口类名(字符串)建立窗口
var
i : integer;
frmTemp : TForm;
cmpOwner : TComponent;
begin
Screen.Cursor := crHourGlass;
try
for i := 0 to Screen.FormCount -1do
if Screen.Forms.ClassName = AClassName then
begin
frmTemp := Screen.Forms;
if frmTemp.WindowState=wsMinimized then
frmTemp.WindowState:=wsNormal;
frmTemp.BringToFront;
frmTemp.Setfocus;
Result := frmTemp;
Exit;
end;

if Assigned(AOwner) then
cmpOwner := AOwner
else
cmpOwner := Application;
Result := nil;
if Assigned(GetClass(AClassName))
and FindClass(AClassName).InheritsFrom(TForm) then
try
Result := TForm(FindClass(AClassName).NewInstance);
Result.Create(cmpOwner);
except
end;
finally
Screen.Cursor := crDefault;
end;
end;

procedure OpenForm(FormClass: TFormClass;
var AForm;
AOwner:TComponent=nil);
//根据窗口类名建立窗口,如果窗口存在则只激活它
var
i: integer;
Child:TForm;
begin
for i := 0 to Screen.FormCount -1do
if Screen.Forms.ClassType=FormClass then
begin
Child:=Screen.Forms;
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;
 
to :c~c
你说的方法我试了,不起作用。
 
initialization
if not Assigned(TggyhF) then
registerClass(TggyhF);

这样呢?
 
后退
顶部