Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Delphi, .NET, Asm (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   Добавление компонентов из dll. (https://forum.antichat.xyz/showthread.php?t=155749)

Proger10 11.11.2009 16:27

Добавление компонентов из dll.
 
Решил в своей программе добавить возможность подключения плагинов. Плагины решил делать dll-ками. Но множество плагинов должны будут добавлять на форму компоненты. Попытался написать в dll:
Код:

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.

, в основном приложении:
Код:

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. Почему и как исправить??

Proger10 16.11.2009 18:07

Ну вот, кое что нашел: класс TLabel в dll<>класс TLabel в приложении.


Время: 15:15