2013-03-02 9 views

回答

6

最有可能的,你將有VCL的兩個實例在你的過程中,一個主機exe文件,一個用於DLL。這是一個例子太多了。宿主exe文件中的TForm類是與DLL中的TForm類不同的類。

的基本規則是,你不能跨模塊邊界共享VCL/RTL對象,除非所有模塊使用VCL/RTL運行的同一個實例。實現這一點的方法是使用包鏈接到VCL/RTL。

+0

喜大衛,因爲我的問題我的DLL來獲取組件列表的工作沒有錯誤,但如果我指定組件「」 Tsomecomponent我得到錯誤。我仍然混亂有關 – AsepRoro 2013-03-11 08:38:38

1

我假設你有一個框架,你有一個TMemo的形式:

聲明兩種類型:

type 
    PTform         = ^TForm; 
    TStringArray       = array of string; 

,使這些可見的EXE和DLL都

.DPR實現部分:

procedure dllcomplist(p_pt_form : PTForm; 
        var p_tx_component : TStringArray); 
      stdcall; 
      external 'dllname.dll'; 

...

var 
    t_tx_component       : TStringArray; 
    t_ix_component       : integer; 

...

Memo1.Lines.Add('Call DLL to return componentlist'); 
    dllcomplist(pt_form,t_tx_component); 
    Memo1.Lines.Add('Result in main program'); 
    for t_ix_component := 0 to pred(length(t_tx_component)) do 
    Memo1.Lines.Add(inttostr(t_ix_component) + '=' + t_tx_component[t_ix_component]); 
    setlength(t_tx_component,0); 

和DLL的.DPR

...

procedure dllcomplist(p_pt_form : PTForm; 
        var p_tx_component : TStringArray); 
      stdcall; 
var 
    t_ix_component       : integer; 
    t_ix_memo        : integer; 
    t_tx_component       : TStringArray; 
begin with p_pt_form^ do begin 
    setlength(t_tx_component,componentcount); 
    setlength(p_tx_component,componentcount); 
    for t_ix_component := 0 to pred(componentcount) do 
    begin 
    t_tx_component[t_ix_component] := components[t_ix_component].Name; 
    p_tx_component[t_ix_component] := components[t_ix_component].Name; 
    if components[t_ix_component].ClassName = 'TMemo' then 
     t_ix_memo := t_ix_component; 
    end; 
    Tmemo(components[t_ix_memo]).lines.add('Within DLL...'); 
    for t_ix_component := 0 to pred(componentcount) do 
    Tmemo(components[t_ix_memo]).lines.add(inttostr(t_ix_component) + ' ' 
      + t_tx_component[t_ix_component]); 
    Tmemo(components[t_ix_memo]).lines.add('DLL...Done'); 
    setlength(t_tx_component,0); 
end; 
end; 

...

exports dllcomplist; 

{OK - 這是更多比嚴格要求複雜。我在做什麼正在建立在調用程序動態數組,它填充在DLL然後在呼叫者顯示結果

AND

檢測TMemo在DLL和從相同的動態寫入數據數組中的DLL到TMemo從來電者 - 顯示的數據是相同}

+0

你還沒有解決的事實DLL.TForm是EXE.TForm不同。這是不可逾越的。 – 2013-03-03 18:56:53

相關問題