用DLL动态调用childform的问题??? |
尚未結案
|
bolidehi
一般會員 ![]() ![]() 發表:11 回覆:11 積分:4 註冊:2004-03-10 發送簡訊給我 |
在一个MIDFORM中的按钮通过DLL调用一个CHILFORM的程式如下:
library childfrm; { 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,
Dialogs,
forms,
Controls,
child in 'child.pas' {childform}; function test(app:tapplication):Tform;stdcall;export;
var
frm:tform;
begin
application:=app;
showmessage('123');
frm:=Tchildform.create(app);
result:=frm;
try
frm.ShowModal;
except
showmessage('错误!');
end; end;
exports
test;
{$R *.res}
begin
end. //CHILDFORM的程式:
unit child; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs; type
Tchildform = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end; var
childform: Tchildform; implementation {$R *.dfm} procedure Tchildform.FormCreate(Sender: TObject);
begin
formstyle:= fsmdichild;
end; procedure Tchildform.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
childform:=nil;
end; end. //MDIFORM程式:
unit mdiform; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
tfunc=function (app:Tapplication):Tform;stdcall;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
var Th:Thandle; Tf:TFunc; Tp:TFarProc;
path:string;
begin
path:=extractfilepath(application.ExeName);
showmessage(path);
Th:=LoadLibrary(pchar(path+'childfrm.dll'));
{装载DLL}
if Th>0 then
try Tp:=GetProcAddress(Th,PChar('test'));
if Tp<>nil then
begin
Tf:=TFunc(Tp);
tf(application);
end
else ShowMessage('TestC函数没有找到'); finally
FreeLibrary(Th); {释放DLL}
end
else ShowMessage('childfrm.dll没有找到');
end;
end. 在调试时在运行到frm.ShowModal出错,麻烦各位指点指点........
|
vagrant
一般會員 ![]() ![]() 發表:29 回覆:72 積分:20 註冊:2003-07-04 發送簡訊給我 |
|
bolidehi
一般會員 ![]() ![]() 發表:11 回覆:11 積分:4 註冊:2004-03-10 發送簡訊給我 |
|
bolidehi
一般會員 ![]() ![]() 發表:11 回覆:11 積分:4 註冊:2004-03-10 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |