各位大虾都说是代码问题。现将部分代码贴出,望予指点:
(以下GPageCtl为TcxPageControl控件)
function CreateForm(AName:string;Sender:TComponent):TForm;
begin
result := nil;
//-------------------------------------基础资料
if AName='备份数据' then
result:= TBackupData.Create(Sender);
if AName='用户管理' then
result:=TfrmUsermnt.Create(Sender);
//......
end;
function FindSheet(ACaption:string):integer;
var
i:integer;
begin
result:=-1;
for i:=0 to GPageCtl.PageCount-1 do begin
if GPageCtl.Pages.Caption=Acaption then begin
result:=i;
break;
end;
end;
end;
function FindForm(ACaption:string;Aactive:boolean=false):TForm;
var
index:integer;
begin
index:=FindSheet(Acaption);
if index>-1 then begin
if Aactive then GPageCtl.ActivePageIndex:=index;
index:=strtointDef(GPageCtl.Pages[index].hint,0);
result:=Tform(Findcontrol(index));
end else result:=nil;
end;
function NewForm(Acaption:string;AnewName:string='';;Apurview:integer=0):Tform;
var
newPage:TcxTabSheet;
frm:Tform;
begin
if AnewName='' then AnewName:=Acaption;
result:=FindForm(AnewName,true);
if result<>nil then exit;
newPage:=TcxTabSheet.Create(GPageCtl);
//creatForm
frm:=createForm(Acaption,newPage,0);
if frm=nil then begin
newPage.Free;
exit;
end;
//newsheet
newPage.PageControl:=GPageCtl;
newPage.Caption:=AnewName;
//creatForm
frm.parent:=newpage;
newPage.Hint:=inttostr(frm.Handle);//在hint中保存frm的handle,以便查找
frm.Name:='F'+newPage.Hint;
frm.Tag:=Apurview;
GPageCtl.Visible:=true;
GPageCtl.ActivePage:=newPage;
frm.Visible:=true;
result:=frm;
end;
//关闭当前sheet
procedure PopFormClose;
begin
with GPageCtl do begin
if PageCount>0 then
ActivePage.free;
Visible:=PageCount>0;
end;
end;