闲时无事,自己根据楼主的需求实现了。 大概思路是,窗体之间调用如楼上各位所说,通过传递TApplication。 如下是B窗体中的代码,可做参考library ProjectC;{ 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, Windows, Forms, UnitC in 'UnitC.pas' {FormC};{$R *.res} var DllApp: TApplication;
function ShowCForm(App: TApplication): Boolean; stdcall; begin Application :=App;{获取调用窗体的Application,显而易见的功能是 能使你的窗体融合到调用程序中。通过它还能进行很多操作} Formc:= TFormc.Create(App); FormC.Show; end;procedure GetParam(var Value: string); stdcall; {通过函数的方式,返回C窗体中的Param得到} begin Value:= FormC.Param;{Param在FormC中定义为全局变量} end;procedure UnLoadForm(Reason: Integer); register; begin {DLL取消调用时,发送DLL_PROCESS_DETACH消息,此时将DLL的Application返回为本身} if Reason = DLL_PROCESS_DETACH then Application:=DLLApp; end;exports ShowCForm, GetParam;begin DLLApp:=Application;{初始化时保存DLL本身Application,以便DLL取消时返回} DLLProc := @UnLoadForm; end.
所以 传入的时候可以用@FORM 其他的都是变量问题了 ~~ 对了 其实函数也可以用@+函数名的 这就是回调函数
就告诉你一下,你只要把 TApplication 从 A 传到 B,从B传到C,
参数,都用 var (甚至用 参数用procedure 或者 function)
没有不能搞头d
这个问题很好啊,需考虑的安全问题很多,
主要是获取Application.Handle的问题,
还有dll窗体关闭时释放问题,
我也试过,但没解决,还得请高手们解决.
大概思路是,窗体之间调用如楼上各位所说,通过传递TApplication。
如下是B窗体中的代码,可做参考library ProjectC;{ 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,
Windows,
Forms,
UnitC in 'UnitC.pas' {FormC};{$R *.res}
var
DllApp: TApplication;
function ShowCForm(App: TApplication): Boolean; stdcall;
begin
Application :=App;{获取调用窗体的Application,显而易见的功能是 能使你的窗体融合到调用程序中。通过它还能进行很多操作}
Formc:= TFormc.Create(App);
FormC.Show;
end;procedure GetParam(var Value: string); stdcall; {通过函数的方式,返回C窗体中的Param得到}
begin
Value:= FormC.Param;{Param在FormC中定义为全局变量}
end;procedure UnLoadForm(Reason: Integer); register;
begin
{DLL取消调用时,发送DLL_PROCESS_DETACH消息,此时将DLL的Application返回为本身}
if Reason = DLL_PROCESS_DETACH then Application:=DLLApp;
end;exports
ShowCForm,
GetParam;begin
DLLApp:=Application;{初始化时保存DLL本身Application,以便DLL取消时返回}
DLLProc := @UnLoadForm;
end.
{ps:CSDN不可以编辑帖子?}