使用函数registerclasses注册的窗体;
创建函数为
procedure TFrmMain.CreateForm(const AFormName,AFormClass: string);
begin
if not assigned(AFormName) then
begin
if getclass(AFormClass) <> nil then
TFormClass(FindClass(AFormClass)).create(self).show;
end;
end;现在问题是执行创建函数FrmMain.CreateForm('form1','TForm1');时无效;
而如果上述创建函数改成
procedure TFrmMain.CreateForm(const AFormName,AFormClass: string);
begin
if getclass(AFormClass) <> nil then
TFormClass(FindClass(AFormClass)).create(self).show;
end;
则又无法限制连续执行;就是一个窗体可以无限次创建。
创建函数为
procedure TFrmMain.CreateForm(const AFormName,AFormClass: string);
begin
if not assigned(AFormName) then
begin
if getclass(AFormClass) <> nil then
TFormClass(FindClass(AFormClass)).create(self).show;
end;
end;现在问题是执行创建函数FrmMain.CreateForm('form1','TForm1');时无效;
而如果上述创建函数改成
procedure TFrmMain.CreateForm(const AFormName,AFormClass: string);
begin
if getclass(AFormClass) <> nil then
TFormClass(FindClass(AFormClass)).create(self).show;
end;
则又无法限制连续执行;就是一个窗体可以无限次创建。
解决方案 »
- dephi webservice 更新数据库记录的问题!
- ClientDataSet 和DataSource连接,并在DBgrid显示-----------------请赐教,,,,
- 一个关于listbox的问题
- 大家帮帮我啊,不要因为分少啊,我是刚注册的呀。
- 表达式a[x]:=a[x]+b[c[y]]如何表达
- ■■■如何将其他应用程序的客户窗口嵌入到我自己编的程序中来?■■■
- 我用DELPHI7写的程序在WIN2000下为什么显示不出控件?
- 哪位仁兄知道 《Delphi5应用程序设计实例》这本书的下载地址
- sql server 2000的datetime数据类型
- 麻烦各位帮我看看是怎么一回事情
- 关于地图放大缩小的问题
- 如何把 编译的 exe 分成多个文件??????????????
if self.MDIChildren[i].Name = AFormName then
begin
formisexist:=true;
self.MDIChildren[i].Show;
break;
end;if not formisexist then
TFormClass(FindClass(AFormClass)).create(self).show;
var AForm: TForm;
begin
if getclass(AFormClass) <> nil then
begin
AForm := TForm(FindComponent(AFormName));
if Assigned(AForm) then
(FindComponent(AFormName) as TFormClass(FindClass(AFormClass))).show
else
TFormClass(FindClass(AFormClass)).create(self).show;
end;
end;
TMenuItem.Tag = (1000000~1000099)
TToolButton.Tag = (1000100~1000199)Create by Lzhang
}unit UMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGridEh, DB, ADODB, PropStorageEh, DBSumLst, DBLookupEh,
DBCtrlsEh, StdCtrls, Mask, PropFilerEh, Buttons, Menus,
ActnList, ComCtrls, ToolWin, ExtCtrls, ImgList, jpeg;const CM_CreateForm = WM_User + 102 ; //生成窗体type
TFrmMain = class(TForm)
ActionList1: TActionList;
ActCreateForm: TAction;
MenuMain: TMainMenu;
N123121: TMenuItem;
NMessageTest: TMenuItem;
NHookTest: TMenuItem;
ToolBar1: TToolBar;
TbtnMessageTest: TToolButton;
TBtnHookTest: TToolButton;
TbtnTypeTest: TToolButton;
ImageList1: TImageList;
NTypeTest: TMenuItem;
Image1: TImage;
TbtnDatabaseTest: TToolButton;
procedure ActCreateFormExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
protected
procedure CMCreateForm(var message: TMessage); message CM_CreateForm;
procedure InitSystem;
public
{ Public declarations }
end;var
FrmMain: TFrmMain;implementation
uses PubDM, clipbrd ;{$R *.dfm}
procedure TFrmMain.FormCreate(Sender: TObject);
begin
InitSystem;
end;procedure TFrmMain.InitSystem;
var I,J: integer;
begin
//初始化ToolButton, TMenuItem控件的点击的点击事件
for I := 0 to FrmMain.ComponentCount - 1 do
with FrmMain.Components[I] do
begin
if (Tag <> 0) and (ClassType <> nil) then
begin
if ClassName = 'TMenuItem' then //Menuitem菜单条的单击事件
begin
TmenuItem(FrmMain.Components[I]).OnClick := ActCreateFormExecute;
end else if ClassName = 'TToolButton' then
begin
TToolButton(FrmMain.Components[I]).OnClick := ActCreateFormExecute;
end
end;
end;
end;
procedure TFrmMain.ActCreateFormExecute(Sender: TObject);
var AFormClass, AFormName: string;
begin
if Sender is TMenuItem then
begin
AFormName := 'Frm'+Copy((sender as TMenuItem).Name,2,length((sender as TMenuItem).Name)-1);
AFormClass := 'T'+AFormCLass;
end else if sender is TToolButton then
begin
AFormName := 'Frm'+Copy((sender as TToolButton).Name,5,length((sender as TToolButton).Name)-1);
AFormClass := 'T'+AFormName;
end; sendmessage(self.Handle,CM_CreateForm,Longint(pchar(AFormClass)),Longint(pchar(AFormName)));
end;procedure TFrmMain.CMCreateForm(var message: TMessage);
var AForm: TForm;
begin
if Getclass(pchar(Message.WParam)) <> nil then
begin
AForm := TForm(FindComponent(pchar(Message.LParam)));
if Assigned(AForm) then
(FindComponent(pchar(Message.LParam)) as TFormClass(FindClass(Pchar(Message.WParam)))).Show
else TFormClass(FindClass(Pchar(Message.WParam))).Create(self).Show;
end;
inherited;
end;end.