T
topdelphi
Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序有三个窗体,其中设置开始启动的是一个验证用户的普通窗体,
验证完用户窗体之后,出现的是一个MDI父窗体,在父窗体里面再打开一个MDI子窗体,
就是这时程序就出错了,显示不了子窗体,出现了下面的错误,请教如何修改这个错误,
project1.exe raised exception class einvalidoperation with message
'cannot create form no mdi forms are currently activel.'
下面分别是我这三个窗体的代码
//普通窗体
procedure Tfrmlogin.cmdokClick(Sender: TObject);
begin
frmmdiform.show;
frmlogin.hide;
end;
//MDI父窗体
procedure Tfrmmain.N2Click(Sender: TObject);
begin
frmuser.open(tfrmuser,frmuser,self);
end;
//MDI子窗体
public
{ Public declarations }
procedure open(formclass:tformclass;var fm;aowner:tcomponent);
var
frmuser: Tfrmuser;
implementation
{$R *.dfm}
procedure tfrmuser.open(formclass:tformclass;var fm;aowner:tcomponent) ;
var
i:integer;
child:tform;
begin
for i:=0 to screen.FormCount -1 do
//找到和FORMCLASS参数相同的窗体,即子窗体已经存在
if screen.Forms.ClassType =formclass then
begin
child:=screen.Forms;
showmessage('你已经打开这个窗体了');
if child.WindowState=wsminimized then //如果子窗体在最小化时处理
showwindow(child.Handle,sw_shownormal)
else
showwindow(child.Handle,sw_showna);
//子窗体为不可视时处理
if (not child.Visible )then child.Visible :=true;
child.BringToFront;//子窗体到顶层窗体
child.SetFocus;//子窗体给焦点
tform(fm):=child;
exit;
end;
//如果子窗体为未打开状态,则新建子窗体
child:=tfrmuser(formclass.NewInstance );
tform(fm):=child;
child.Create(aowner);
end;
procedure Tfrmuser.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
end;
验证完用户窗体之后,出现的是一个MDI父窗体,在父窗体里面再打开一个MDI子窗体,
就是这时程序就出错了,显示不了子窗体,出现了下面的错误,请教如何修改这个错误,
project1.exe raised exception class einvalidoperation with message
'cannot create form no mdi forms are currently activel.'
下面分别是我这三个窗体的代码
//普通窗体
procedure Tfrmlogin.cmdokClick(Sender: TObject);
begin
frmmdiform.show;
frmlogin.hide;
end;
//MDI父窗体
procedure Tfrmmain.N2Click(Sender: TObject);
begin
frmuser.open(tfrmuser,frmuser,self);
end;
//MDI子窗体
public
{ Public declarations }
procedure open(formclass:tformclass;var fm;aowner:tcomponent);
var
frmuser: Tfrmuser;
implementation
{$R *.dfm}
procedure tfrmuser.open(formclass:tformclass;var fm;aowner:tcomponent) ;
var
i:integer;
child:tform;
begin
for i:=0 to screen.FormCount -1 do
//找到和FORMCLASS参数相同的窗体,即子窗体已经存在
if screen.Forms.ClassType =formclass then
begin
child:=screen.Forms;
showmessage('你已经打开这个窗体了');
if child.WindowState=wsminimized then //如果子窗体在最小化时处理
showwindow(child.Handle,sw_shownormal)
else
showwindow(child.Handle,sw_showna);
//子窗体为不可视时处理
if (not child.Visible )then child.Visible :=true;
child.BringToFront;//子窗体到顶层窗体
child.SetFocus;//子窗体给焦点
tform(fm):=child;
exit;
end;
//如果子窗体为未打开状态,则新建子窗体
child:=tfrmuser(formclass.NewInstance );
tform(fm):=child;
child.Create(aowner);
end;
procedure Tfrmuser.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
end;