Добавление компонентов из dll.

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by Proger10, 11 Nov 2009.

  1. Proger10

    Proger10 Member

    Joined:
    19 Dec 2008
    Messages:
    80
    Likes Received:
    7
    Reputations:
    0
    Решил в своей программе добавить возможность подключения плагинов. Плагины решил делать dll-ками. Но множество плагинов должны будут добавлять на форму компоненты. Попытался написать в dll:
    Code:
    library DllPlug;
    
    { 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
      Forms,
      StdCtrls;
    
    {$R *.res}
    
    procedure Exec(Form: TForm);
    var
      l: TLabel;
    begin
      l:=TLabel.Create(Form);
      l.Parent:=Form;
      l.Caption:='I''m adding Label from dll!';
    end;
    
    exports
      Exec;
    
    begin
    end.
    , в основном приложении:
    Code:
    unit Unit1;
    
    interface
    
    uses
      Windows, Forms, StdCtrls;
    
    type
      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
      Exec : procedure (Form: TForm);
      Handle : Thandle;
    begin
      handle := LoadLibrary('dllplug.dll');
      if handle <> 0 then
      begin
        @Exec := GetProcAddress(handle,'Exec');
          Exec(Form1);
      end;
      FreeLibrary(handle);
    end;
    
    end.
    В итоге когда жму на кнопку - Cannnot assign TFont to a TFont. Почему и как исправить??
     
    #1 Proger10, 11 Nov 2009
    Last edited: 12 Nov 2009
  2. Proger10

    Proger10 Member

    Joined:
    19 Dec 2008
    Messages:
    80
    Likes Received:
    7
    Reputations:
    0
    Ну вот, кое что нашел: класс TLabel в dll<>класс TLabel в приложении.