DLL中使用的组件TcxCheckListBox的错误属性ImageIndex

时间:2019-02-08 09:25:44

标签: delphi

测试:

  1. Delphi 7 + DevExpress 6.59
  2. Delphi 10.2 + DevExpress 18.1

如果在应用程序项目中实现

lst1.Items[0].ImageIndex := 0

好吧

如果在DLL项目中实现

lst1.Items[0].ImageIndex := 0

重画组件时导致严重错误。

  

访问冲突的地址为00000000。读取的地址为00000000。

如果此参数设置了设计时间,则会出现相同的错误。

这是一个非常好的组件可视化链接TcxCheckListBox + ImageList。 如何在DLL中实现?

项目应用

unit uMain;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TForm1 = class(TForm)
    btnLoadForm: TButton;
    procedure btnLoadFormClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  MyLoadForm : function (h : THandle) : Integer stdcall;
implementation
{$R *.dfm}
procedure TForm1.btnLoadFormClick(Sender: TObject);
var
  LibHandle : THandle;
  x : Integer;
begin
  LibHandle := LoadLibrary('MYDLL.DLL');
  if LibHandle >= 32 then
  begin
    @MyLoadForm := GetProcAddress(LibHandle,'MyLoadForm');
    if @MyLoadForm <> nil then
    begin
      x:= MyLoadForm(Application.Handle);
    end;
  end;
end;

项目DLL

library myDll;
uses
  SysUtils,
  Classes,
  Dialogs,
  Forms,
  uDllForm in 'uDllForm.pas' {Form1},
  windows;
{$R *.res}
function MyLoadForm(AppHandle : THandle) : integer stdcall;
var
  dllform: TForm1;
begin
  Application.Handle := AppHandle;
  dllform:=TForm1.Create(Application);
  dllform.ShowModal;
  Result := 1;
end;
exports
  MyLoadForm;
begin
end.

单元格+ TcxCheckListBox对象

unit uDllForm;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, ImgList, CheckLst, cxContainer, cxEdit,
  cxCheckListBox;
type
  TForm1 = class(TForm)
    btn1: TButton;
    lst1: TcxCheckListBox;
    il1: TImageList;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var st : string;
begin
  lst1.Items[0].Text := 'test';
  lst1.Items[0].ImageIndex := 0;
end;
end.

0 个答案:

没有答案