将对象实例发送到 DLL 进行处理?

Sending an object instance to a DLL for processing?

我在 Delphi 10.3.3 中创建了一个 DLL 并编译了它(作为 32 位):

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.

然后在 Delphi 10.3.3 我创建了一个 VCL 应用程序来托管 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.

这是表格文件'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

这是项目文件'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.

单击该按钮会将面板着色为红色。

为什么它不起作用,我怎样才能让它起作用?

还请通过代码或在 dfm 中将 pnlTestParentBackground 设置为 false