如题,调用该对象又该怎么办?

解决方案 »

  1.   

    用指针
    library Dll;
    uses
    SysUtils,windows,
    Classes,Controls,Forms,
    DllForm in 'DllForm.pas' ;
    {$R *.res}
    var
    DllApp:TApplication;
    { 用于初始化:保存DLL本身的Application,然后设置DLL的Application指向Host的Application }
    procedure InitDLL(App:TApplication);stdcall;
    begin
    DllApp:=Application;
    Application:=App;
    end;
    { 善后工作:恢复DLL原来的Application }
    procedure FreeDLL;stdcall;
    begin
    Application:=DllApp;
    end;
    { 返回一个窗体对象,这是DLL的主要功能 }
    function GetDllChildForm(Parent:TComponent):TFrmDLLChild;stdcall;
    begin
    Result := TFrmDLLChild.Create(Parent);
    end;
    exports
    InitDLL,FreeDLL,GetDllChildForm;
    begin
    end.function GetDllChildForm(Parent:TComponent):TFrmDllChild;stdcall;external 'dll.dll';
    procedure InitDLL(App:TApplication);stdcall;external 'dll.dll';
    procedure FreeDLL;stdcall;external 'dll.dll';
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    InitDLL(Application);
    end;
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    FreeDLL;
    end;
    调用窗体代码:
    var
    DForm:TFrmDllChild;
    begin
    DForm :=DllFunction(Application,Self);
    DForm.Show;
    end;
      

  2.   

    仔细看这一篇文章,非常清楚:
    http://dev.csdn.net/article/29/29053.shtm
      

  3.   

    我认为要在DLL导出的Class,最好使用Interface!(有点矛盾)也就是说,你要导出的是一个接口指针DLL里面用Class实现Interface,在你的程序里就直接借口,但用的是Class,多态性就是这个道理个人看法
      

  4.   

    dext(德克斯特)建议很不错的。
    这样有很好的二进制兼容性,在C++也能使用这个对象。