请教:当调用DLL中的父窗体,子窗体时,怎么解决找不到父窗体的情况?谢谢 ( 积分: 50 )

  • 主题发起人 zenghc80
  • 开始时间
Z

zenghc80

Unregistered / Unconfirmed
GUEST, unregistred user!
我开发的一个模块是用父,子窗体实现的,现在要求把它变成动态链接库(DLL),当外面的程序调用这个DLL时,DLL中的主窗体能调出来,但当调用子窗体时,提示:Cannot create form,No MDI Forms are currently active;
找不到活动的父窗体?我现在已经传了一个Application参数进DLL了,是什么原因?怎么解决,敬请高手帮助解决!!!
 
我开发的一个模块是用父,子窗体实现的,现在要求把它变成动态链接库(DLL),当外面的程序调用这个DLL时,DLL中的主窗体能调出来,但当调用子窗体时,提示:Cannot create form,No MDI Forms are currently active;
找不到活动的父窗体?我现在已经传了一个Application参数进DLL了,是什么原因?怎么解决,敬请高手帮助解决!!!
 
留下Email 给你例子
 
zenggh80@yahoo.com.cn
太谢谢了,呵呵
 
还有传递一人screen进去。
 
to Avalon:也给我一个这样的例子好吗?我也正为这事烦哩.
lnming@yeah.net
 
to Avalon;
我还没收到你发的,请你再发一遍好吗,谢谢
 
//一个插件的例子
www.hitekersoft.com/download/Plugins.rar
 
zenggh80@yahoo.com.cn
 
//一个插件的例子
www.hitekersoft.com/download/Plugins.rar
下载完毕通知一声,我要删除
 
to xianguo:
已经下载完了,谢谢!,呵呵 ,等结贴的时候再给分吧
 
to xianguo:
非常感谢你的支持,我看了一下你的例子,一般的情况下是可以这样的,但当做成DLL的时候就不行了,不知你试过吗,如果DLL还行的话,请告知,谢谢
 
to delphigbg:
传screen? 不知道是怎么传的,现在我的DLL中已经有了父,子窗体.
 
Main是主程序,Serach是dll插件
主程序自动加载插件
(程序已经经过测试)
 
to delphigbg:
你好,呵呵 ,可能是我的水平有问题吧 ,现在子窗体是能出现了,但DLL还是报错,感觉我这个DLL写的还是有点问题,如果你方便的话,可以用qq联系吗?(qq:22430769)
 
我的例子还没有收到
 
to Avalon;
你好,你的例子还没收到,呵呵,能再发一遍吗?(zenggh80@yahoo.com.cn)
 
大哥,大姐们:
我的这个问题还没有解决啊,谁能帮我???
 
给你一个例子
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus;
type
TLoadFrm = procedure(App: TApplication;
Scr: TScreen );
StdCall;
TForm2 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure N2Click(Sender: TObject);
private
DllHandle: Cardinal;
public
{ Public declarations }
end;

var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if DllHandle <> 0 then
FreeLibrary(DllHandle);
end;

procedure TForm2.N2Click(Sender: TObject);
var
LoadFrm: TLoadFrm;
begin
DllHandle := LoadLibrary(Pchar('F:/Component/Dllfrm/Order/prDll.dll'));
if DllHandle <= 0 then
Exit;
LoadFrm := GetProcAddress(DllHandle, PChar('LoadFrm'));
if @LoadFrm = nil then
Exit;
LoadFrm(Application, Screen);
end;

end.

2.DLL部分:
library prDll;
uses
SysUtils,
Classes,
Forms,
Windows,
Unit3 in 'Unit3.pas' {Form3},
Unit4 in 'Unit4.pas';
{$R *.RES}
Exports
LoadFrm;
var
GApplication: TApplication ;
GScreen: TScreen;
procedure InitDll(dWseason: DWORD);
begin
case dWseason of
DLL_PROCESS_ATTACH: begin
GApplication := Application;
GScreen := Screen;
end;
DLL_PROCESS_DETACH: begin
Application := GApplication;
Screen := GScreen;
end;
end;
end;
begin
DllProc := @InitDll;
InitDll(DLL_PROCESS_ATTACH);
end.
DLL 包含的窗体:
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm3 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;
implementation
{$R *.DFM}
procedure TForm3.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
Form3 := nil;
end;
end.
DLL 包含的公共单元(主要是函数书写):
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Unit3;
procedure LoadFrm(App: TApplication;
Scr: TScreen);
StdCall;
implementation
procedure LoadFrm(App: TApplication;
Scr: TScreen );
var
LPtr: PLongint;
begin
if Form3 <> nil then
Exit;
Application := App;
Screen := Scr;

LPtr := @Application.MainForm;
LPtr^ := Longint(App.MainForm);
Form3 := TForm3.Create(App.MainForm);
Form3.Show;
end;
end.
 
顶部