線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1471
推到 Plurk!
推到 Facebook!

請問各位先進如何將 靜態式呼叫DLL 改成 動態式呼叫DLL

答題得分者是:maplefog
shine0989
一般會員


發表:9
回覆:31
積分:8
註冊:2008-06-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-05-07 16:35:09 IP:123.204.xxx.xxx 訂閱
各位先進大家好~
小弟這個問題己經困擾我一個多月了 ><"
害小弟睡覺都會做惡夢

小弟的問題是
以下的程式碼使用靜態式呼叫DLL的方式是可以正常開啟的

但是小弟想要更進一步的進行改成動態式呼叫DLL的方式
可是卻一直報錯><"

希望各位先進能指點小弟...
在此先感謝...!

以下為MAINFORM的程式

[code delphi]

//這是靜態呼叫DLL的方式
function GetChildForm8(MDIMainForm: TForm; AClassName: string; var f: TForm): Boolean; external 'DLL_acct7.dll';

//如今我改成我要的動態呼叫DLL的方式如下↓
TGetChildForm8 = function (MDIMainForm: TForm; AClassName: string; var f: TForm): Boolean; stdcall;

//當我按下BUTTON就把DLL的FORM\開出來
procedure TMainForm.Button1Click(Sender: TObject);
var
GetChildForm8 : TGetChildForm8;
ADllHandle : THandle;
ProcAddr : FarProc;
f : TForm;
begin

ADllHandle := LoadLibrary('DLL_acct7.dll');


try
if ADllHandle<>0 then
ProcAddr := GetProcAddress(ADllHandle, 'GetChildForm8');

if ProcAddr<>nil then
begin
GetChildForm8(Self,'acct7',f);
end;

finally
FreeLibrary(ADllHandle);
end;
end;

[/code]


以下為DLL的程式

[code delphi]

library DLL_acct7;

{ 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
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
acct7f in 'acct7f.pas' {acct7},
shitemf in 'shitemf.pas' {shitem},
shcusf in 'shcusf.pas' {shcus};

{$R *.res}
function GetChildForm8(MDIMainForm: TForm; AClassName: string; var f: TForm): Boolean;
var
I: Integer;
begin
f := nil;
for I := 0 to MDIMainForm.MDIChildCount-1 do
begin
if MDIMainForm.MDIChildren[I].ClassNameIs(AClassName) then
begin
f := MDIMainForm.MDIChildren[I];
Break;
end;
end;

if f = nil then
begin
if AClassName = 'acct7' then f := Tacct7.Create(MDIMainForm)
end;
Result := f <> nil;

end;

exports GetChildForm8;
begin
end.

[/code]



shine0989
一般會員


發表:9
回覆:31
積分:8
註冊:2008-06-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-05-10 11:35:52 IP:123.204.xxx.xxx 訂閱
自己頂一下..><"

請各位先進能指點小弟..!!
maplefog
一般會員


發表:16
回覆:24
積分:13
註冊:2008-11-08

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-05-10 12:38:00 IP:140.118.xxx.xxx 訂閱
這篇就有動態的寫法了

http://delphi.ktop.com.tw/board.php?cid=30&fid=70&tid=69648


shine0989
一般會員


發表:9
回覆:31
積分:8
註冊:2008-06-21

發送簡訊給我
#4 引用回覆 回覆 發表時間:2010-05-10 17:51:41 IP:123.204.xxx.xxx 訂閱

===================引 用 maplefog 文 章===================
這篇就有動態的寫法了

http://delphi.ktop.com.tw/board.php?cid=30&fid=70&tid=69648



非常非常感謝maplefog大大的指點..^^

小弟終於結決囉了...^^


系統時間:2024-05-04 9:22:36
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!