I have created a DLL in Delphi 10.3.3 and compiled it (as 32-bit):
library TestDLL;
uses
Vcl.ExtCtrls,
Vcl.Graphics,
System.SysUtils,
System.Classes;
{$R *.res}
procedure ColorPanel(APanel: TPanel);
begin
APanel.Color := clRed;
end;
exports
ColorPanel;
begin
end.
Then in Delphi 10.3.3 I created a VCL application to host the DLL:
unit Main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TForm3 = class(TForm)
pnlTest: TPanel;
btnTest: TButton;
procedure btnTestClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure ColorPanel(APanel: TPanel); external 'TestDLL.dll';
procedure TForm3.btnTestClick(Sender: TObject);
begin
ColorPanel(pnlTest);
end;
end.
This is the form file 'Main.dfm':
object Form3: TForm3
Left = 0
Top = 0
Caption = 'Form3'
ClientHeight = 217
ClientWidth = 359
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
PixelsPerInch = 120
TextHeight = 16
object pnlTest: TPanel
Left = 0
Top = 0
Width = 153
Height = 217
Align = alLeft
Caption = 'pnlTest'
TabOrder = 0
end
object btnTest: TButton
Left = 208
Top = 24
Width = 75
Height = 25
Caption = 'Test'
TabOrder = 1
OnClick = btnTestClick
end
end
And this is the project file 'TestDLL.dpr':
program DllHost;
uses
Vcl.Forms,
Main in 'Main.pas' {Form3};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm3, Form3);
Application.Run;
end.
Clicking on the button should colorize the panel red.
Why does it not work and how can I make it work?