在你的每一个窗体的源文件中加入: implementation{$R *.DFM} initialization RegisterClass(TForm2);////注册窗体类名称 在你的主程序当中: type FormClass=class of TForm;procedure TForm1.Button1Click(Sender: TObject); var pForm:TForm; Temp:TPersistentClass; begin Temp:=GetClass('TForm2'); if Temp<>nil then begin pForm:=TForm(FormClass(Temp).Create(Application)); pForm.ShowModal; pForm.Free; end; end;
To:quark(夸克) ; 你可真黑,这种问题没必要那么多分吧。 TO:huangbin277 (王凌烽) : 下面这段就是你要的: procedure TMainForm.OpenForm(FormClass: TFormClass; var MyForm;CaptionStr,sFlag: string); var i: integer; Child: TForm; AvailRes:Integer; version_no:Integer; ss:string; begin Version_no:=GetVersion(); //得到系统版本号 if Version_no<0 then begin AvailRes:=GetusableWinResource();//得到系统资源 if AvailRes<12 then begin Application.MessageBox('系统资源不足!','警告',mb_Ok); Exit; end; end; if MDIChildCount>3 then begin Application.MessageBox('子窗体过多!','警告',Mb_Ok); Exit; end; if not JudgePower then //判断权限 Exit; for i:=0 to Screen.FormCount-1 do begin if Screen.Forms[i].ClassType=FormClass then begin Application.MessageBox('你已经打开这个窗体!','警告',Mb_ok); Exit; end; end; Child:=TForm(FormClass.NewInstance); TForm(MyForm) := Child; Child.Create(AOwner); Child:=FormClass.Create(Self); Child.Show; Child.Caption := CaptionStr; end;
//============================================================================== //1.菜单执行,创建或显示窗体**************************************************** //============================================================================== procedure Menu_Executive(MenuItem: TMenuItem); //var i, j, k, ControlIndex: integer; var i, j, ControlIndex: integer; WebParam, BrowserName: string; begin //============================================================================ //打开帮助******************************************************************** //============================================================================ if MenuItem=Form_Main.N_Help_Topic then begin Application.HelpFile := VG_AppHelp; Application.helpcommand(help_finder,0);//显示索引页 Exit; end; //============================================================================ //打开浏览器,指向公司网站**************************************************** //============================================================================ if MenuItem=Form_Main.N_Help_WebBrowser then begin BrowserName := GetBrowserNameAndParam(WebParam); GotoWeb(Form_Main.Handle, 0, BrowserName, WebParam, 'www.bdxc.com', SW_SHOWNORMAL); Exit; end; //============================================================================ //所有DataModule和ShowModal形式的子窗口*************************************** //============================================================================ for i:=0 to Echos.Count-1 do//在MenuArray内搜索 if MenuItem=TEcho(Echos.Items[i]).Menu then//如果主窗口单击的菜单等于MenuArray[i] begin//0 if TEcho(Echos.Items[i]).Dockable then//如果是Dockable类型 try ControlIndex := -1; for j:=1 to Form_Main.Panel_Main.ControlCount do//则首先将Form_Main.Panel_Main内的所有控制隐藏 begin Form_Main.Panel_Main.Controls[j-1].Tag := 1;//并所有隐藏的控件Tag值为1 Form_Main.Panel_Main.Controls[j-1].Hide; if TEcho(Echos.Items[i]).InstanceClass.ClassName=Form_Main.Panel_Main.Controls[j-1].ClassName then ControlIndex := j-1; end; //==================================================================== if ControlIndex>0//如果呼叫的子窗口已经存在 then begin Form_Main.TabControl.TabIndex := ControlIndex; Form_Main.Panel_Main.Controls[ControlIndex].Tag := 0;//当前显示的控件Tag值为0 Form_Main.Panel_Main.Controls[ControlIndex].Show;//则显示该子窗口 if TDockForm_Data(Form_Main.Panel_Main.Controls[ControlIndex]).dsBrowse//根据子窗口是否处于浏览状态 then Form_Main.Data_State(true, true, true, false, false, true, true, true, true)//决定'新增'、'删除'、'修改'、'保存'、'撤消'、'打印'状态 else Form_Main.Data_State(false, false, false, true, true, false, false, false, false); end else begin//如果呼叫的子窗口不存在 Application.CreateForm(TEcho(Echos.Items[i]).InstanceClass, TEcho(Echos.Items[i]).Reference);//则创建该子窗口 Form_Main.TabControl.Tabs.Add((TEcho(Echos.Items[i]).Reference as TForm).Caption);//Form_Main.TabControl增加子项 Form_Main.TabControl.TabIndex := Form_Main.TabControl.Tabs.Count - 1; (TEcho(Echos.Items[i]).Reference as TForm).Dock(Form_Main.Panel_Main, Form_Main.Panel_Main.ClientRect); (TEcho(Echos.Items[i]).Reference as TForm).Tag := 0;//当前显示的控件Tag值为0 (TEcho(Echos.Items[i]).Reference as TForm).Show; TDockForm_Data(TEcho(Echos.Items[i]).Reference as TForm).dsBrowse := true;//子窗口创建时默认为浏览状态 Form_Main.Data_State(true, true, true, false, false, true, true, true, true); //============================================================= //选择‘操作员’所属部门*************************************** //============================================================= { if Form_Main.ToolButton_Governor.Down then for k:=1 to DockForm_Tree.Tree_Governor.Items[0].Count do if Copy(DockForm_Tree.Tree_Governor.Items[0].Item[k-1].Text,6,255)=VG_Group then DockForm_Tree.Tree_Governor.Items[0].Item[k-1].Selected := true; } end; finally end else begin//ShowModal形式的子窗口 Application.CreateForm(TEcho(Echos.Items[i]).InstanceClass, TEcho(Echos.Items[i]).Reference);//则创建该子窗口 try (TEcho(Echos.Items[i]).Reference as TForm).ShowModal; finally (TEcho(Echos.Items[i]).Reference as TForm).Free; end; end; Break; end;//0 end;
implementation{$R *.DFM}
initialization
RegisterClass(TForm2);////注册窗体类名称
在你的主程序当中:
type
FormClass=class of TForm;procedure TForm1.Button1Click(Sender: TObject);
var
pForm:TForm;
Temp:TPersistentClass;
begin
Temp:=GetClass('TForm2');
if Temp<>nil then
begin
pForm:=TForm(FormClass(Temp).Create(Application));
pForm.ShowModal;
pForm.Free;
end;
end;
你可真黑,这种问题没必要那么多分吧。
TO:huangbin277 (王凌烽) :
下面这段就是你要的:
procedure TMainForm.OpenForm(FormClass: TFormClass; var MyForm;CaptionStr,sFlag: string);
var
i: integer;
Child: TForm;
AvailRes:Integer;
version_no:Integer;
ss:string;
begin
Version_no:=GetVersion(); //得到系统版本号
if Version_no<0 then
begin
AvailRes:=GetusableWinResource();//得到系统资源
if AvailRes<12 then
begin
Application.MessageBox('系统资源不足!','警告',mb_Ok);
Exit;
end;
end;
if MDIChildCount>3 then
begin
Application.MessageBox('子窗体过多!','警告',Mb_Ok);
Exit;
end;
if not JudgePower then //判断权限
Exit;
for i:=0 to Screen.FormCount-1 do
begin
if Screen.Forms[i].ClassType=FormClass then
begin
Application.MessageBox('你已经打开这个窗体!','警告',Mb_ok);
Exit;
end;
end;
Child:=TForm(FormClass.NewInstance);
TForm(MyForm) := Child;
Child.Create(AOwner);
Child:=FormClass.Create(Self);
Child.Show;
Child.Caption := CaptionStr;
end;
//==============================================================================
//在本系统中所有的主窗口菜单与子窗口都是通过MenuRecord类型的MenuArray数组关联在一起
//==============================================================================
type TEcho = class(TObject)
Menu: TMenuItem;
Reference: TComponent;
InstanceClass: TComponentClass;
Dockable: Boolean;
end;
var Echos: TList; procedure Menu_Point;
procedure Menu_Executive(MenuItem: TMenuItem); implementation
uses //=========================================================================
//主程序*******************************************************************
//=========================================================================
Main, Main_System,
//=========================================================================
//用户*********************************************************************
//=========================================================================
User_Cell, {居民用户}
User_Corp, {单位用户} //=========================================================================
//系统*********************************************************************
//=========================================================================
System_Popedom, {操作权限}
System_Client, {客户端状态}
//=========================================================================
//帮助*********************************************************************
//=========================================================================
Help_About; //==============================================================================
//0.构造菜单指向窗体记录********************************************************
//==============================================================================
procedure Menu_Point;
//============================================================================
//1.构造菜单指向窗体记录******************************************************
//============================================================================
procedure MenuPointForm(Menu: TMenuItem; Reference: TComponent; InstanceClass: TComponentClass; Dockable: Boolean);{Annal:记录}
begin
Echos.Add(Pointer(TEcho.Create));
TEcho(Echos.Items[Echos.Count-1]).Menu := Menu;
TEcho(Echos.Items[Echos.Count-1]).Reference := Reference;
TEcho(Echos.Items[Echos.Count-1]).InstanceClass := InstanceClass;
TEcho(Echos.Items[Echos.Count-1]).Dockable := Dockable;
end;
//==============================================================================
begin
Echos := TList.Create;
//============================================================================
//主窗口菜单指向不同Dock子窗口************************************************
//============================================================================
with Form_Main do
begin
//==========================================================================
//用户_居民用户*************************************************************
//==========================================================================
MenuPointForm(N_User_Cell, Form_Cell, TForm_Cell, true);
//==========================================================================
//用户_单位用户*************************************************************
//==========================================================================
MenuPointForm(N_User_Corp, Form_Corp, TForm_Corp, true);
//==========================================================================
//系统_客户端状态***********************************************************
//==========================================================================
MenuPointForm(N_System_Client, Form_Client, TForm_Client, false);
//==========================================================================
//帮助_关于*****************************************************************
//==========================================================================
MenuPointForm(N_Help_About, Form_About, TForm_About, false);
//============================================================================
end;
end;
//1.菜单执行,创建或显示窗体****************************************************
//==============================================================================
procedure Menu_Executive(MenuItem: TMenuItem);
//var i, j, k, ControlIndex: integer;
var i, j, ControlIndex: integer;
WebParam, BrowserName: string;
begin
//============================================================================
//打开帮助********************************************************************
//============================================================================
if MenuItem=Form_Main.N_Help_Topic then
begin
Application.HelpFile := VG_AppHelp;
Application.helpcommand(help_finder,0);//显示索引页
Exit;
end;
//============================================================================
//打开浏览器,指向公司网站****************************************************
//============================================================================
if MenuItem=Form_Main.N_Help_WebBrowser then
begin
BrowserName := GetBrowserNameAndParam(WebParam);
GotoWeb(Form_Main.Handle, 0, BrowserName, WebParam, 'www.bdxc.com', SW_SHOWNORMAL);
Exit;
end;
//============================================================================
//所有DataModule和ShowModal形式的子窗口***************************************
//============================================================================
for i:=0 to Echos.Count-1 do//在MenuArray内搜索
if MenuItem=TEcho(Echos.Items[i]).Menu then//如果主窗口单击的菜单等于MenuArray[i]
begin//0
if TEcho(Echos.Items[i]).Dockable then//如果是Dockable类型
try
ControlIndex := -1;
for j:=1 to Form_Main.Panel_Main.ControlCount do//则首先将Form_Main.Panel_Main内的所有控制隐藏
begin
Form_Main.Panel_Main.Controls[j-1].Tag := 1;//并所有隐藏的控件Tag值为1
Form_Main.Panel_Main.Controls[j-1].Hide;
if TEcho(Echos.Items[i]).InstanceClass.ClassName=Form_Main.Panel_Main.Controls[j-1].ClassName
then ControlIndex := j-1;
end;
//====================================================================
if ControlIndex>0//如果呼叫的子窗口已经存在
then begin
Form_Main.TabControl.TabIndex := ControlIndex;
Form_Main.Panel_Main.Controls[ControlIndex].Tag := 0;//当前显示的控件Tag值为0
Form_Main.Panel_Main.Controls[ControlIndex].Show;//则显示该子窗口
if TDockForm_Data(Form_Main.Panel_Main.Controls[ControlIndex]).dsBrowse//根据子窗口是否处于浏览状态
then Form_Main.Data_State(true, true, true, false, false, true, true, true, true)//决定'新增'、'删除'、'修改'、'保存'、'撤消'、'打印'状态
else Form_Main.Data_State(false, false, false, true, true, false, false, false, false);
end
else begin//如果呼叫的子窗口不存在
Application.CreateForm(TEcho(Echos.Items[i]).InstanceClass, TEcho(Echos.Items[i]).Reference);//则创建该子窗口
Form_Main.TabControl.Tabs.Add((TEcho(Echos.Items[i]).Reference as TForm).Caption);//Form_Main.TabControl增加子项
Form_Main.TabControl.TabIndex := Form_Main.TabControl.Tabs.Count - 1;
(TEcho(Echos.Items[i]).Reference as TForm).Dock(Form_Main.Panel_Main, Form_Main.Panel_Main.ClientRect);
(TEcho(Echos.Items[i]).Reference as TForm).Tag := 0;//当前显示的控件Tag值为0
(TEcho(Echos.Items[i]).Reference as TForm).Show;
TDockForm_Data(TEcho(Echos.Items[i]).Reference as TForm).dsBrowse := true;//子窗口创建时默认为浏览状态
Form_Main.Data_State(true, true, true, false, false, true, true, true, true);
//=============================================================
//选择‘操作员’所属部门***************************************
//=============================================================
{
if Form_Main.ToolButton_Governor.Down
then for k:=1 to DockForm_Tree.Tree_Governor.Items[0].Count do
if Copy(DockForm_Tree.Tree_Governor.Items[0].Item[k-1].Text,6,255)=VG_Group
then DockForm_Tree.Tree_Governor.Items[0].Item[k-1].Selected := true;
}
end;
finally end
else begin//ShowModal形式的子窗口
Application.CreateForm(TEcho(Echos.Items[i]).InstanceClass, TEcho(Echos.Items[i]).Reference);//则创建该子窗口
try
(TEcho(Echos.Items[i]).Reference as TForm).ShowModal;
finally
(TEcho(Echos.Items[i]).Reference as TForm).Free;
end;
end;
Break;
end;//0
end;