MDI窗体退出时提示出错?(急,一定给分)

tfm 2003-06-19 10:15:34
我做的程序是主窗体是MDIForm,然后每个MDIChild是用DLL的方式做的,每个字窗体的显示和关闭都没有问题,就是所有的字窗体都关闭后,关主窗体的时候,提示"内存读取出错,请问该怎么解决" ;我用的是静态调用;
代码如下:
DLL
library Project1;



{$R *.res}
var
DLLApp: TApplication;
DLLScr: TScreen;

procedure DLLEntryPoint(dwReason: DWORD);
begin
case dwReason of
DLL_PROCESS_ATTACH:
begin
DLLScr := Screen;
DLLApp := Application;
end;
DLL_PROCESS_DETACH:
begin
Screen := DllScr;
Application := DllApp;
end;
end;
end;

//// 运行DLL主窗口 //////////////////////////////////////
function RunApp(AApplication: TApplication; AScreen: TScreen):TForm1; stdcall;
begin

Screen := AScreen;
Application := AApplication;
Form1 := TForm1.Create(Application);
Form1.Show;
result:=form1;
end;

//////////////////////////////////////////////////////////////////////
exports
RunApp;

//////////////////////////////////////////////////////////////
begin
DLLProc := @DLLEntryPoint; //Assign the address of DLLEntryPoint to DLLProc
DLLEntryPoint(DLL_PROCESS_ATTACH); //Indicate that the DLL is attaching to the process
end.
主窗体是这样调用的
function RunApp(AApplication: TApplication; AScreen: TScreen;DBCON:TADOConnection):Tform; stdcall;external 'dll\project1.dll' ;
主窗体关闭时
procedure TF_Main.FormClose(Sender: TObject; var Action: TCloseAction);
var
i:integer;
begin

for I := MDIChildCount - 1 downto 0 do
begin
MDIChildren[I].Close;
MDIChildren[I].Free;
end;
end;
请各位帮忙看看
...全文
40 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sherry3000 2003-06-19
  • 打赏
  • 举报
回复
内存释放问题最麻烦。我前天的函数接口发现某些时候会出来地址错误,昨天只好全部重新写了。真是累呀!
boz 2003-06-19
  • 打赏
  • 举报
回复
在dll中子窗体的OnDestroy事件中加入例如Form1:=nil,释放子窗体
flyfish99 2003-06-19
  • 打赏
  • 举报
回复
就是我也出现过这种问题
而且查了一下相关帖子
他们是关闭动态创建窗体:freeandnil(formname)
但是我用来释放控件,就不行;也说是只读属性~郁闷ing,但是提问也没人提出个所以然~

这个内存释放问题,强烈关注~
tfm 2003-06-19
  • 打赏
  • 举报
回复
没有办法加,提示MDIChildren[I]是只读属性,没法改变.
boz 2003-06-19
  • 打赏
  • 举报
回复
主窗体关闭时
procedure TF_Main.FormClose(Sender: TObject; var Action: TCloseAction);
var
i:integer;
begin

for I := MDIChildCount - 1 downto 0 do
begin
MDIChildren[I].Close;
MDIChildren[I].Free;
MDIChildren[I]=nil; //add this
end;
end;
Means_pan 2003-06-19
  • 打赏
  • 举报
回复
帮你up

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧