delphi窗体新建和关闭的问题
我有一个MDI主窗体,两个MDI子窗体,主窗体打开子窗体代码如下:procedureTMainForm.N7Click(Sender:TObject);vari:Inte...
我有一个MDI主窗体,两个MDI子窗体,主窗体打开子窗体代码如下:
procedure TMainForm.N7Click(Sender: TObject);
var
i:Integer;
begin
if assigned(form5) then
begin
for i :=0 to MainForm.MDIChildCount -1 do
if (MainForm.MDIChildren[i] is tForm5) then
begin
self.MDIChildren[i].BringToFront;
MDIChildren[i].SetFocus;
Exit;
end;
end
else
begin
Application.CreateForm(TForm5,Form5);
Form5.Show;
end;
end;
procedure TMainForm.N8Click(Sender: TObject);
var
i:Integer;
begin
if Assigned(Form11) then
begin
for i:=0 to MainForm.MDIChildCount-1 do
if (MainForm.MDIChildren[i] is TForm11) then
begin
Self.MDIChildren[i].BringToFront;
MDIChildren[i].SetFocus;
Exit;
end;
end
else
begin
Application.CreateForm(TForm11,Form11);
Form11.Show;
end;
end;
Form5和Form11的FormClose里面写了Action:=cafree; FormDestroy里面分别写了
Form5:=nil; Form11:=nil;
现问题是如果是打开单个窗体,怎么操作都没有问题,如果同时打开两个窗体,在关闭时就会报错:Access violation at adress 0055dd7f in module mdiapp.exe
请问这个该怎么解决
Action:=caFree; 我也有写这句,但不知为什么不行 ,如果不写Form5:=nil这句,那么这个子窗体关闭后,再点就打不开 展开
procedure TMainForm.N7Click(Sender: TObject);
var
i:Integer;
begin
if assigned(form5) then
begin
for i :=0 to MainForm.MDIChildCount -1 do
if (MainForm.MDIChildren[i] is tForm5) then
begin
self.MDIChildren[i].BringToFront;
MDIChildren[i].SetFocus;
Exit;
end;
end
else
begin
Application.CreateForm(TForm5,Form5);
Form5.Show;
end;
end;
procedure TMainForm.N8Click(Sender: TObject);
var
i:Integer;
begin
if Assigned(Form11) then
begin
for i:=0 to MainForm.MDIChildCount-1 do
if (MainForm.MDIChildren[i] is TForm11) then
begin
Self.MDIChildren[i].BringToFront;
MDIChildren[i].SetFocus;
Exit;
end;
end
else
begin
Application.CreateForm(TForm11,Form11);
Form11.Show;
end;
end;
Form5和Form11的FormClose里面写了Action:=cafree; FormDestroy里面分别写了
Form5:=nil; Form11:=nil;
现问题是如果是打开单个窗体,怎么操作都没有问题,如果同时打开两个窗体,在关闭时就会报错:Access violation at adress 0055dd7f in module mdiapp.exe
请问这个该怎么解决
Action:=caFree; 我也有写这句,但不知为什么不行 ,如果不写Form5:=nil这句,那么这个子窗体关闭后,再点就打不开 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询