求“DLL里面封装了子窗”的成熟调用方法。 ( 积分: 100 )

L

lcm40

Unregistered / Unconfirmed
GUEST, unregistred user!
本人最近在做一个ERP系统,采用了EXE(主程序)+DLL(里面封装了子窗体和各种数据的处理)方式。现在遇到的问题是:1、程序使用一段时间(30分钟)后会报内存地址溢出等错误;2、DLL(封装了子窗体)如何动态释放?3、说明一下,我想求比较成熟的方法,最好是已经商用的方法,请各位高手帮忙。
 
U

uranuszh

Unregistered / Unconfirmed
GUEST, unregistred user!
你的问题只能是你传程序过来,我给你排错误. 架构没错,是可以实现的。
我采用.exe 调用 无模式dll窗体正常使用超过2年。
可以用qq联系: 23635869
 
J

JackCn009

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在是不释放的:(
 
J

JackCn009

Unregistered / Unconfirmed
GUEST, unregistred user!
uranuszh 我用exe调dll窗体都是没有释放的,能发份例子给我看看吗,感激不尽
lxjmail@163.com
 
W

wrf

Unregistered / Unconfirmed
GUEST, unregistred user!
可能是你的界面控件的问题
 
G

guanyue7613

Unregistered / Unconfirmed
GUEST, unregistred user!
DLL_PROCESS_DETACH: //判断 DLL退出 ,进行释放资源等处理
 
O

otqsoft

Unregistered / Unconfirmed
GUEST, unregistred user!
在主控台中用链表管理你的子窗体(可以是DLL中的窗体),当DLL中窗体关闭时要向主控台发一条消息,在链表时释放掉就行了!
 
L

lisongmagic

Unregistered / Unconfirmed
GUEST, unregistred user!
像dll中的窗体一般用模态窗体,这样其内存比较容易控制,而不要交给其主属性如application等处理,做个小例子供你参考一下:(已调试,运行ok)
unit DLLForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TfrmDLL = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmDLL: TfrmDLL;
procedure SynAPP(App:THandle);stdcall;
procedure ShowForm;stdcall;
implementation
uses Math;
{$R *.dfm}
procedure SynAPP(App:THandle );stdcall;
begin
Application.Handle := App;
end;

procedure ShowForm;stdcall;
begin
try
frmDLL := TfrmDLL.Create (Application);
try
frmDLL.ShowModal;
finally
frmDLL.Free;
end;
except
on E: Exceptiondo
MessageDlg ('Error in DLLForm: ' +
E.Message, mtError, [mbOK], 0);
end;
end;

procedure TfrmDLL.Button1Click(Sender: TObject);
begin
Color := RandomRange(0,255 * 255 * 255 );
end;

end.
*************************************************
library FormDLL;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
Forms,
DLLForm in 'DLLForm.pas' {frmDLL};

{$R *.res}
exports
SynAPP,ShowForm;
begin
end.

****************************************************************
unit testDLLForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
procedure SynAPP(App:THandle);stdcall;external 'FormDLL.dll';
procedure ShowForm;stdcall;external 'FormDLL.dll';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SynApp(Application.Handle );
ShowForm ;
end;

end.
 
Q

QSmile

Unregistered / Unconfirmed
GUEST, unregistred user!
ChildForm
我试了很多方法,用了 TBX 就很难办了.
不用TBX 都好办. 就是要传 Application 与 Screen 就可以了.
 
L

lcm40

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢各位高手的热心帮助,能不能贴点成熟的调用代码,不胜感激!
 
P

ppqingyu

Unregistered / Unconfirmed
GUEST, unregistred user!
我调用DLL子窗体是DLL+BPL实现的
 
L

lcm40

Unregistered / Unconfirmed
GUEST, unregistred user!
QQ:39745011
Email:wlls790708@163.com
有成熟调用方法的高手请和我联系,在些先谢谢啦!
 
L

louqing_2

Unregistered / Unconfirmed
GUEST, unregistred user!
谁有好的方法,也给我一份啊,我也没有想通怎么用的?
我的EMAIL:LOUQING_2@163.COM
 
L

lisongmagic

Unregistered / Unconfirmed
GUEST, unregistred user!
好贴不要沉
顶顶顶顶顶顶顶顶顶顶顶
 
L

lisongmagic

Unregistered / Unconfirmed
GUEST, unregistred user!
不是吧,还没搞定?你最好把代码写严谨更规范点:
模式窗体:
if not Assigned(aForm1)then
aForm1:= TForm1.Create(nil);
try
if aForm1.ShowModal = mrOk then
//do sth.
finally
aForm1.Free;
aForm1:= nil;
end;

非模式窗体:
if not Assigned(aForm1)then
aForm1:= TForm1.Create(nil);
aForm1.Show;
然后在每个窗体的onclose和onDestroy事件中写上以下代码,我不相信还会有问题:
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:= caFree;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
aForm1:= nil;
end;

我不相信这还还会有什么内存溢出等问题,
dll封装子窗体,不就这么简单的事吗
 
S

ssstudio

Unregistered / Unconfirmed
GUEST, unregistred user!
我都不知道封闭了多少了,留个数据源接口,以后直接调用就可以使用了
 
W

wlls

Unregistered / Unconfirmed
GUEST, unregistred user!
大家的方法我都试过了,DLL(封装了子窗体)如何动态释放的问题一直没有得到很好的解决。请大家继续帮忙。在此先谢谢大家。成功后马上给分!
 
B

bbscom

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在解决了这个方案。
1、主程序EXE和DLL业务模块是分开的。
2、EXE + MDI + DLL + DCOM 架构。
3、动态释放FREE的DLL。
4、变量可以在EXE或DLL相互使用。
 
L

lcm40

Unregistered / Unconfirmed
GUEST, unregistred user!
bbscom:
能不提供具体一点的资料。
 
顶部