窗体创建问题 ( 积分: 200 )

  • 主题发起人 主题发起人 zhg88888
  • 开始时间 开始时间
Z

zhg88888

Unregistered / Unconfirmed
GUEST, unregistred user!
Application.CreateForm(FormClass: TFormClass;
var Reference) ;
在其中我有很多个已设计好的窗体,我想用一个公用过程进行创建,如下:
Procedure pCreateForm(fName:String)
begin

end ;
请问在中间怎样用Application.CreateForm()实现?
 
Application.CreateForm(FormClass: TFormClass;
var Reference) ;
在其中我有很多个已设计好的窗体,我想用一个公用过程进行创建,如下:
Procedure pCreateForm(fName:String)
begin

end ;
请问在中间怎样用Application.CreateForm()实现?
 
by jfyes modify
// 调用检查Forms
function TTaiShing.ShowForm(FormClass: TFormClass): TForm;
var
I: Integer;
begin
try
result := nil;
for I := 0 to Screen.FormCount - 1do
if Screen.Forms.ClassNameIs(FormClass.ClassName) then
begin
result := Screen.Forms;
break;
end;
if result = nil then
Application.CreateForm(FormClass, result);
if result <>
nil then
begin
if result.WindowState = wsMinimized then
ShowWindow(result.Handle, SW_RESTORE)
else
result.BringToFront;
end;
except
on E: Exception
do
raise E.Create(E.Message);
end;
end;

// 调用检查Forms
procedure TTaiShing.FindShowForm(FormClass: TFormClass;
var Form);
var
I: Integer;
begin
try
TCustomForm(Form) := nil;
for I := 0 to Screen.FormCount - 1do
if Screen.Forms.ClassNameIs(FormClass.ClassName) then
begin
TCustomForm(Form) := Screen.Forms;
break;
end;
if TCustomForm(Form) = nil then
begin
Application.CreateForm(FormClass, Form);

end;
if TCustomForm(Form).WindowState = wsMinimized then
ShowWindow(TCustomForm(Form).Handle, SW_RESTORE)
else
TCustomForm(Form).BringToFront;
except
on E: Exception
do
raise E.Create(E.Message);
end;
end;
 
多谢!我先试一下!
 
//unit Unit1;
function ApplicationCreateForm(FormClassName: string;
var Reference): Boolean;
var
PersistentClass: TPersistentClass;
FormClass: TFormClass;
begin
Result:= False;
PersistentClass:= GetClass(FormClassName);
if Assigned(PersistentClass) and PersistentClass.InheritsFrom(TForm) then
try
FormClass:= TFormClass(PersistentClass);
Application.CreateForm(FormClass, Reference);
Result:= True;
except
Raise EAbort.Create('ApplicationCreateForm('+FormClassName+') failed!');
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ApplicationCreateForm('TForm2', Form2);
Form2.ShowModal;
Form2.Free;
Form2:= nil;
end;

//unit Unit2;
var
Form2: TForm2;
implementation
{$R *.dfm}
initialization
RegisterClass(TForm2);
finalization
UnRegisterClass(TForm2);
end.

 
jfyes:大哥,不行啊
 
把你写的代码贴出来看看是什么问题?
 
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, SConnect, Buttons, ExtCtrls, DBCtrls,
Grids, DBGrids, StdCtrls, StrUtils, Menus, ActnList, XPStyleActnCtrls,
ActnMan, AppEvnts, ComCtrls, StatusBarEx, ObjBrkr, XPMenu, UnlimitedMenu,
DBClientActns, DBActns, ImgList, ToolWin, ActnCtrls;
type
TMainForm = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
StatusBarEx1: TStatusBarEx;
A6011: TMenuItem;
N10: TMenuItem;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
N15: TMenuItem;
N16: TMenuItem;
N17: TMenuItem;
N18: TMenuItem;
ImageList1: TImageList;
amFunction: TActionManager;
A101: TAction;
A102: TAction;
dsMain: TDataSource;
A103: TAction;
A111: TAction;
A112: TAction;
A121: TAction;
A122: TAction;
A123: TAction;
N19: TMenuItem;
N20: TMenuItem;
A201: TAction;
A202: TAction;
A203: TAction;
A204: TAction;
A205: TAction;
A206: TAction;
A401: TAction;
A402: TAction;
A403: TAction;
A404: TAction;
A405: TAction;
A407: TAction;
A408: TAction;
A409: TAction;
A410: TAction;
A411: TAction;
A412: TAction;
A413: TAction;
A414: TAction;
A415: TAction;
A406: TAction;
A801: TAction;
A802: TAction;
A803: TAction;
A804: TAction;
N21: TMenuItem;
N22: TMenuItem;
N23: TMenuItem;
N24: TMenuItem;
N25: TMenuItem;
N26: TMenuItem;
N27: TMenuItem;
N28: TMenuItem;
N29: TMenuItem;
N30: TMenuItem;
N31: TMenuItem;
N32: TMenuItem;
N33: TMenuItem;
N34: TMenuItem;
N35: TMenuItem;
N36: TMenuItem;
N37: TMenuItem;
N38: TMenuItem;
N39: TMenuItem;
N40: TMenuItem;
N41: TMenuItem;
N42: TMenuItem;
N43: TMenuItem;
N44: TMenuItem;
N45: TMenuItem;
N46: TMenuItem;
N47: TMenuItem;
N48: TMenuItem;
N49: TMenuItem;
A905: TAction;
A906: TAction;
A907: TAction;
A908: TAction;
A909: TAction;
A910: TAction;
A911: TAction;
N50: TMenuItem;
N51: TMenuItem;
N52: TMenuItem;
N53: TMenuItem;
N54: TMenuItem;
N55: TMenuItem;
N56: TMenuItem;
XPStyle: TXPMenu;
procedure A101Execute(Sender: TObject);
private
Procedure atForm(iFormid:Integer) ;
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;
implementation
uses Employee, Organise, DMSystems;
{$R *.dfm}
procedure TMainForm.atForm(iFormid: Integer);
begin
case iFormid of
101:DMSystem.Form.Locate('FormId',iFormid,[oPartialKey])
102: ;
end;
//其中DMSystem.Form.FieldByName('FormName').AsString就是窗体名,我怎么样用下面的函数实现创建出来?
Application.CreateForm()
end;

procedure TMainForm.A101Execute(Sender: TObject);
begin
atForm(StrToInt(Copy(TAction(Sender).Name,2,3))) ;
end;

end.
 
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, SConnect, Buttons, ExtCtrls, DBCtrls,
Grids, DBGrids, StdCtrls, StrUtils, Menus, ActnList, XPStyleActnCtrls,
ActnMan, AppEvnts, ComCtrls, StatusBarEx, ObjBrkr, XPMenu, UnlimitedMenu,
DBClientActns, DBActns, ImgList, ToolWin, ActnCtrls;
type
TMainForm = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
StatusBarEx1: TStatusBarEx;
A6011: TMenuItem;
N10: TMenuItem;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
N15: TMenuItem;
N16: TMenuItem;
N17: TMenuItem;
N18: TMenuItem;
ImageList1: TImageList;
amFunction: TActionManager;
A101: TAction;
A102: TAction;
dsMain: TDataSource;
A103: TAction;
A111: TAction;
A112: TAction;
A121: TAction;
A122: TAction;
A123: TAction;
N19: TMenuItem;
N20: TMenuItem;
A201: TAction;
A202: TAction;
A203: TAction;
A204: TAction;
A205: TAction;
A206: TAction;
A401: TAction;
A402: TAction;
A403: TAction;
A404: TAction;
A405: TAction;
A407: TAction;
A408: TAction;
A409: TAction;
A410: TAction;
A411: TAction;
A412: TAction;
A413: TAction;
A414: TAction;
A415: TAction;
A406: TAction;
A801: TAction;
A802: TAction;
A803: TAction;
A804: TAction;
N21: TMenuItem;
N22: TMenuItem;
N23: TMenuItem;
N24: TMenuItem;
N25: TMenuItem;
N26: TMenuItem;
N27: TMenuItem;
N28: TMenuItem;
N29: TMenuItem;
N30: TMenuItem;
N31: TMenuItem;
N32: TMenuItem;
N33: TMenuItem;
N34: TMenuItem;
N35: TMenuItem;
N36: TMenuItem;
N37: TMenuItem;
N38: TMenuItem;
N39: TMenuItem;
N40: TMenuItem;
N41: TMenuItem;
N42: TMenuItem;
N43: TMenuItem;
N44: TMenuItem;
N45: TMenuItem;
N46: TMenuItem;
N47: TMenuItem;
N48: TMenuItem;
N49: TMenuItem;
A905: TAction;
A906: TAction;
A907: TAction;
A908: TAction;
A909: TAction;
A910: TAction;
A911: TAction;
N50: TMenuItem;
N51: TMenuItem;
N52: TMenuItem;
N53: TMenuItem;
N54: TMenuItem;
N55: TMenuItem;
N56: TMenuItem;
XPStyle: TXPMenu;
procedure A101Execute(Sender: TObject);
private
Procedure atForm(iFormid:Integer) ;
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;
implementation
uses Employee, Organise, DMSystems;
{$R *.dfm}
procedure TMainForm.atForm(iFormid: Integer);
begin
case iFormid of
101:DMSystem.Form.Locate('FormId',iFormid,[oPartialKey])
102: ;
end;
//其中DMSystem.Form.FieldByName('FormName').AsString就是窗体名,我怎么样用下面的函数实现创建出来?
Application.CreateForm()
end;

procedure TMainForm.A101Execute(Sender: TObject);
begin
atForm(StrToInt(Copy(TAction(Sender).Name,2,3))) ;
end;

end.
 
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
DBClientActns, DBActns, ImgList, ToolWin, ActnCtrls;
type
TMainForm = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
ImageList1: TImageList;
amFunction: TActionManager;
A101: TAction;
A102: TAction;
dsMain: TDataSource;
A103: TAction;
A201: TAction;
XPStyle: TXPMenu;
procedure A101Execute(Sender: TObject);
private
Procedure atForm(iFormid:Integer) ;
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
uses Employee, Organise, DMSystems;
{$R *.dfm}
procedure TMainForm.atForm(iFormid: Integer);
begin
case iFormid of
101:DMSystem.Form.Locate('FormId',iFormid,[oPartialKey])
102: ;
end;
//其中DMSystem.Form.FieldByName('FormName').AsString就是窗体名,我怎么样用下面的函数实现创建出来?(窗体在上面的Uses列表中已包含)
Application.CreateForm()
end;

procedure TMainForm.A101Execute(Sender: TObject);
begin
atForm(StrToInt(Copy(TAction(Sender).Name,2,3))) ;
end;

end.
 
后退
顶部