我已经在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中将ParentBackground
的pnlTest
设置为false
。>
解决方案是将pnlTest.ParentBackground
设置为FALSE
。现在可以正常工作: