看我这个,用rztabs的。unit INXITEUnit;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ImgList, ActnList, ADODB, ShellAPI, MainUnit, ComCtrls, Menus, ExtCtrls, RzPanel, RzSplit, RzGroupBar, RzTabs, DB, //新增加的FrameUnit列在这儿 USRTOOLSEDTFRAMEUnit, AUTOJOBUnit, BaseFrameUnit, TblClassUnit, TblQueryFrameUnit, GKDataFrameUnit, TblRecordQueryFrameUnit, UserGroupManagerFrameUnit, TblRecordEditFrameUnit // ;type TINXITEForm = class(TForm) ilINXITE: TImageList; actlstINXITE: TActionList; actTBCX: TAction; actTBPL: TAction; actYTZSD: TAction; actZTGKMK: TAction; actJK: TAction; actDSRWPZ: TAction; ActCloseActivePage: TAction; actCloseAllPage: TAction; actExit: TAction; statINXITE: TStatusBar; mmINXITE: TMainMenu; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; N4: TMenuItem; N5: TMenuItem; N6: TMenuItem; NTools: TMenuItem; N7: TMenuItem; NHelp: TMenuItem; rzszpnlLeft: TRzSizePanel; rzgrpbrLeft: TRzGroupBar; rzgrp1: TRzGroup; rzgrp2: TRzGroup; rzgrp3: TRzGroup; rzpgcntrlINXITE: TRzPageControl; actTYGJPZ: TAction; qryEdit: TADOQuery; { Private declarations } procedure SelectPage(PageIdx: Integer); procedure NewPage(strTitle: string; AddRecord: Boolean = False; FSQL: string = ''; FGUID: string = ''); // procedure CloseAll; procedure actExitExecute(Sender: TObject); //关闭所有Frame窗口 procedure INXITEActExecute(Sender: TObject); //执行打开Frame操作 procedure INXITEToolsMenuItemClick(Sender: Tobject); //通用工具菜单点击 procedure actCloseAllPageExecute(Sender: TObject); //关闭所有Frame procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure ActCloseActivePageExecute(Sender: TObject); //关闭当前Frame procedure SetINXITEPriv; //设置Action的Enable procedure AddToolsMenu; procedure FormActivate(Sender: TObject); procedure rzpgcntrlINXITEClose(Sender: TObject; var AllowClose: Boolean); //设置Tools菜单的Item procedure DelPage(strTitle: string); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); public { Public declarations } procedure AddPage(strTitle: string; AddRecord: Boolean = False; FSQL: string = ''; FGUID: string = ''); procedure ClosePage(strtitle: string); end;var INXITEForm: TINXITEForm; PageList: TStringList; //声明的Frame变量加在这儿 UsrToolsEdtFrame: TUSRTOOLSEDTFrame; AutoJobFrame: TAUTOJOBFrame; TblClassFrame: TTBLClassFrame; TblQueryFrame: TTBLQueryFrame; GKDataFrame: TGKDataFrame; tmpTblRecordQueryFrame: TTblRecordQueryFrame; UserGroupManagerFrame: TUserGroupManagerFrame; tmpTblRecordEditFrame: TTblRecordEditFrame; //implementation{$R *.dfm}{ TINXITEForm }procedure TINXITEForm.AddPage(strTitle: string; AddRecord: Boolean = False; FSQL: string = ''; FGUID: string = '');var PageIdx: integer;begin//增加页面 PageIdx := PageList.IndexOf(strTitle); if PageIdx <> -1 then SelectPage(PageIdx) else NewPage(strTitle, AddRecord, FSQL, FGUID);end;procedure TINXITEForm.CloseAll;var PageIdx: integer;begin//在这儿释放所有的Frame,并删除TabSheet for PageIdx := rzpgcntrlINXITE.PageCount - 1 downto 0 do DelPage(rzpgcntrlINXITE.Pages[PageIdx].Caption);end;procedure TINXITEForm.DelPage(strTitle: string);var PageIdx, ObjectIdx: integer; tmpTab: TRzTabSheet;begin//关闭页面,先清空Frame,再删除TabSheet对象 PageIdx := PageList.IndexOf(strTitle); if PageIdx <> -1 then begin tmpTab := (PageList.Objects[PageIdx] as TRzTabSheet); for ObjectIdx := tmpTab.ControlCount - 1 downto 0 do begin //先调用FreeAll来清空一些动态建立的资源 if strTitle = '通用工具配置' then USRTOOLSEDTFrame.FreeAll; if strTitle = '定时任务配置' then AUTOJOBFrame.FreeAll; if strTitle = '库表分类' then TblClassFrame.FreeAll; if strTitle = '库表查询' then TblQueryFrame.FreeAll; if strTitle = '逐条公开模块' then GKDataFrame.FreeAll; if pos('表记录查询', strTitle) > 0 then begin tmpTblRecordQueryFrame := (tmpTab.Controls[ObjectIdx] as TTblRecordQueryFrame); tmpTblRecordQueryFrame.FreeAll; end; if pos('表记录编辑', strTitle) > 0 then begin tmpTblRecordEditFrame := (tmpTab.Controls[ObjectIdx] as TTblRecordEditFrame); tmpTblRecordEditFrame.FreeAll; //这儿要做一些记录的定位处理,查找原来的表记录查询窗口,并定位等操作 end; if strTitle = '用户组设定' then UserGroupManagerFrame.FreeAll; (tmpTab.Controls[ObjectIdx] as TControl).Free; end; tmpTab.Free; PageList.Delete(PageIdx); end;end;procedure TINXITEForm.NewPage(strTitle: string; AddRecord: Boolean = False; FSQL: string = ''; FGUID: string = '');var NewTab: TRzTabSheet;begin NewTab := nil; if strTitle = '通用工具配置' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := '通用工具配置'; NewTab.PageControl := rzpgcntrlINXITE; USRTOOLSEDTFrame := TUSRTOOLSEDTFrame.Create(Application); USRTOOLSEDTFrame.Parent := NewTab; USRTOOLSEDTFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; UsrToolsEdtFrame.Init; end; if strTitle = '定时任务配置' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; AutoJobFrame := TAUTOJOBFrame.Create(Application); AutoJobFrame.Parent := NewTab; AutoJobFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; AutoJobFrame.Init; end; if strTitle = '库表分类' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; TblClassFrame := TTBLClassFrame.Create(Application); TblClassFrame.Parent := NewTab; TblClassFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; TblClassFrame.Init; end; if strTitle = '库表查询' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; TblQueryFrame := TTBLQueryFrame.Create(Application); TblQueryFrame.Parent := NewTab; TblQueryFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; TblQueryFrame.Init; end; if strTitle = '逐条公开模块' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; GkDataFrame := TGKDataFrame.Create(Application); GKDataFrame.Parent := NewTab; GKDataFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; GKDataFrame.Init; end; if pos('表记录查询', strTitle) > 0 then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; tmpTblRecordQueryFrame := TTblRecordQueryFrame.Create(Application); tmpTblRecordQueryFrame.Parent := NewTab; tmpTblRecordQueryFrame.Align := alClient; tmpTblRecordQueryFrame.Name := 'Qry' + copy(strTitle, 11, Length(strTitle)); rzpgcntrlINXITE.ActivePage := NewTab; tmpTblRecordQueryFrame.FrameCaption := strTitle; tmpTblRecordQueryFrame.TableName := copy(strTitle, 11, Length(strTitle)); tmpTblRecordQueryFrame.Init; end; if Pos('表记录编辑', strTitle) > 0 then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; tmpTblRecordEditFrame := TTblRecordEditFrame.Create(Application); tmpTblRecordEditFrame.Parent := NewTab; tmpTblRecordEditFrame.Align := alClient; tmpTblRecordEditFrame.Name := 'Edt' + copy(strTitle, 11, Length(strTitle)); rzpgcntrlINXITE.ActivePage := NewTab; tmpTblRecordEditFrame.FrameCaption := strTitle; tmpTblRecordEditFrame.TableName := copy(strTitle, 11, Length(strTitle)); tmpTblRecordEditFrame.AddRecord := AddRecord; //新增 true 编辑 false tmpTblRecordEditFrame.GUID := FGUID; //定位GUId tmpTblRecordEditFrame.SQL := FSQL; //SQL语句 tmpTblRecordEditFrame.Init; end; if strTitle = '用户组设定' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; UserGroupManagerFrame := TUserGroupManagerFrame.Create(Application); UserGroupManagerFrame.Parent := NewTab; UserGroupManagerFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; UserGroupManagerFrame.Init; end; if NewTab <> nil then PageList.AddObject(strTitle, NewTab);end;procedure TINXITEForm.SelectPage(PageIdx: Integer);var ActivePage: TRzTabSheet;begin// if PageList.Objects[PageIdx] <> nil then begin ActivePage := (PageList.Objects[PageIdx] as TRzTabSheet); rzpgcntrlINXITE.ActivePage := ActivePage; end;end;procedure TINXITEForm.actExitExecute(Sender: TObject);begin CloseAll; Close;end;procedure TINXITEForm.INXITEActExecute(Sender: TObject);begin AddPage((Sender as TAction).Caption);end;procedure TINXITEForm.INXITEToolsMenuItemClick(Sender: Tobject);begin if FileExists((Sender as TMenuItem).Hint) then ShellExecute(handle, 'open', pchar((Sender as TMenuItem).Hint), '', '', SW_SHOW) else ShowMessage('可执行文件不存在,请通知系统管理员!!!');end;procedure TINXITEForm.actCloseAllPageExecute(Sender: TObject);begin CloseAll;end;procedure TINXITEForm.FormCreate(Sender: TObject);begin PageList := TStringList.Create;end;procedure TINXITEForm.FormDestroy(Sender: TObject);begin PageList.Free;end;procedure TINXITEForm.ActCloseActivePageExecute(Sender: TObject);begin ClosePage(rzpgcntrlINXITE.ActivePage.Caption);end;procedure TINXITEForm.SetINXITEPriv;var GrpPrivLst: TStringList; GrpPriv: string; i: Integer; clsName: string;begin//根据用户权限,设置INXITE主界面上的可操作项 GrpPrivLst := TStringList.Create; qryEdit.Close; qryEdit.SQL.Text := 'SELECT A.GUIPRIV FROM' + ' USR_GROUP A,GAZX30USER B' + ' WHERE B.USERNAME=''' + MainForm.G_CZY + '''' + ' AND B.GRPPRIV=A.T_USR_GROUP_NAME'; qryEdit.Open; GrpPriv := qryEdit.FieldByName('GUIPRIV').AsString; MainForm.SplitString(GrpPriv, ',', GrpPrivLst); for i := 0 to INXITEForm.ComponentCount - 1 do if INXITEForm.Components.Tag > 0 then begin clsName := INXITEForm.Components.ClassName; if clsName = 'TAction' then (INXITEForm.Components as TAction).Enabled := (GrpPrivLst.IndexOf((INXITEForm.Components as TAction).Caption) <> -1) end; for i := 0 to NTools.Count - 1 do NTools.Items.Enabled := (GrpPrivLst.IndexOf(NTools.Items.Caption) <> -1); GrpPrivLst.Free;end;procedure TINXITEForm.AddToolsMenu;var tmpAdoQuery: TADOQuery; i: Integer; tmpMenuItem: TMenuItem;begin//根据用户权限,生成用户可使用的通用工具列表//先清空Tools菜单 for i := NTools.Count - 1 downto 0 do NTools.Items.Free;//再生成Tools菜单 tmpAdoQuery := TADOQuery.Create(nil); tmpAdoQuery.Connection := MainForm.UserADOConnection; tmpAdoQuery.SQL.Text := 'SELECT TOOLNAME,TOOLFILENAME FROM USR_TOOLS WHERE ENABLED=1'; tmpAdoQuery.Open; while not tmpAdoQuery.Eof do begin tmpMenuItem := TMenuItem.Create(nil); tmpMenuItem.Caption := tmpAdoQuery.fieldbyname('TOOLNAME').AsString; tmpMenuItem.Hint := tmpAdoQuery.fieldByname('TOOLFILENAME').AsString; tmpMenuItem.Tag := 1; tmpMenuItem.OnClick := INXITEToolsMenuItemClick; NTools.Add(tmpMenuItem); tmpAdoQuery.Next; end; tmpAdoQuery.Close; FreeAndNil(tmpAdoQuery);end;procedure TINXITEForm.FormActivate(Sender: TObject);begin statINXITE.Panels[1].Text := MainForm.G_CZY; AddToolsMenu; SetINXITEPriv;end;procedure TINXITEForm.rzpgcntrlINXITEClose(Sender: TObject; var AllowClose: Boolean);begin ActCloseActivePageExecute(Self);end;procedure TINXITEForm.ClosePage(strtitle: string);begin DelPage(strtitle); if rzpgcntrlINXITE.PageCount > 0 then rzpgcntrlINXITE.ActivePageIndex := rzpgcntrlINXITE.PageCount - 1;end;procedure TINXITEForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);begin CloseAll; CanClose := True;end;end.