Delphi XE4 E2010 不兼容的类型:“Cardinal”和“Pointer”

Posted

技术标签:

【中文标题】Delphi XE4 E2010 不兼容的类型:“Cardinal”和“Pointer”【英文标题】:Delphi XE4 E2010 Incompatible types: 'Cardinal' and 'Pointer' 【发布时间】:2013-09-01 07:13:10 【问题描述】:

你好,我试图在delphi xe4下编译firedac dll开发示例,结果出现以下错误

[dcc32 Error] Unit1.pas(61): E2010 Incompatible types: 'Cardinal' and 'Pointer'

我已经在代码中标出了错误的位置。

单元 1 是可执行文件。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uADStanIntf, uADStanOption, uADStanDef, uADPhysIntf,
  uADDatSManager, uADStanParam, uADDAptIntf, StdCtrls, Grids, DBGrids,
  DB, uADPhysManager, uADPhysMSAcc, uADGUIxFormsWait, uADCompGUIx, uADCompDataSet,
  uADCompClient, uADStanError, uADGUIxIntf, uADStanPool, uADStanAsync,
  uADDAptManager, uADPhysODBCBase;

type
  TShowDataProc = procedure (ACliHandle: LongWord); stdcall;
  TShutdownProc = procedure; stdcall;

  TForm1 = class(TForm)
    ADConnection1: TADConnection;
    ADQuery1: TADQuery;
    ADGUIxWaitCursor1: TADGUIxWaitCursor;
    ADPhysMSAccessDriverLink1: TADPhysMSAccessDriverLink;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    FhDll: THandle;
    FpShowData: TShowDataProc;
    FpShutdown: TShutdownProc;
  end;

var
  Form1: TForm1;

implementation

$R *.dfm

uses
  uADStanUtil;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FhDll := LoadLibrary(PChar('Project2.dll'));
  if FhDll = 0 then
    raise Exception.Create(ADLastSystemErrorMsg);
  @FpShowData := GetProcAddress(FhDll, PChar('ShowData'));
  if not Assigned(FpShowData) then
    raise Exception.Create(ADLastSystemErrorMsg);
  @FpShutdown := GetProcAddress(FhDll, PChar('Shutdown'));
  if not Assigned(FpShutdown) then
    raise Exception.Create(ADLastSystemErrorMsg);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  FpShowData(ADConnection1.CliHandle);   << Error is here
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  FpShutdown();
  FreeLibrary(FhDll);
  FhDll := 0;
  @FpShowData := nil;
  @FpShutdown := nil;
end;

end.

Unit2 是 dll

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uADStanIntf, uADStanOption, uADStanDef, uADPhysIntf,
  uADDatSManager, uADStanParam, uADDAptIntf, Grids, DBGrids, DB,
  uADPhysManager, uADPhysMSAcc, uADGUIxFormsWait, uADCompGUIx, uADCompDataSet,
  uADCompClient, uADStanError, uADGUIxIntf, uADStanPool, uADStanAsync,
  uADDAptManager, uADPhysODBCBase;

type
  TForm2 = class(TForm)
    ADConnection1: TADConnection;
    ADQuery1: TADQuery;
    ADGUIxWaitCursor1: TADGUIxWaitCursor;
    ADPhysMSAccessDriverLink1: TADPhysMSAccessDriverLink;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
  public
    class procedure ShowData(ACliHandle: LongWord);
  end;

var
  Form2: TForm2;

implementation

$R *.dfm

 TForm2 

class procedure TForm2.ShowData(ACliHandle: LongWord);
var
  oForm: TForm2;
begin
  oForm := TForm2.Create(Application);
  oForm.ADConnection1.SharedCliHandle := ACliHandle;  <<<<<<<<<Error Here
  oForm.ADConnection1.Connected := True;
  oForm.ADQuery1.Active := True;
  oForm.Show;
end;

end.

【问题讨论】:

我只是猜测。也许 SharedCliHandle 在内部始终是指针,并且只是以长字形式呈现,以便更轻松地使用此属性。 x32 模式可以,但 x64 模式不行(指针是 64 位,但长字是 32 位)。因此,也许他们将 SharedCliHandle 的类型更改为指针(至少对于 x64 模式),只需检查它的类型,即使您没有源代码也可以在 IDE 中进行。 【参考方案1】:

http://docs.embarcadero.com/products/rad_studio/firedac/frames.html?frmname=topic&frmfile=uADCompClient_TADCustomConnection_SharedCliHandle.html

正如您所见,SharedCliHandle 是指针,所以可能示例是旧的,您需要将 LongWord 更改为指针。为什么之前是 LongWord 而指针现在我们只能猜测,我的猜测是我作为评论分享的。

【讨论】:

感谢您将 longword 更改为 ACliHandle 的指针,它编译时没有错误。我知道 embarcadero 从 da-soft 购买了 fireac,但他们需要针对 XE4 等较新 IDE 的新示例项目

以上是关于Delphi XE4 E2010 不兼容的类型:“Cardinal”和“Pointer”的主要内容,如果未能解决你的问题,请参考以下文章

delphi xe4 Firemonkey 3D程序 xp环境下,TText是字体问题

delphi XE4多线程critical section问题

设置Delphi XE4默认界面样式

delphi XE4生成ipa并部署到越狱iPad视频教程

Delphi XE4 + Indy TCP服务器:大量线程

Delphi XE4或XE5:如何以弹出格式打开Goog le Chrome?