Delphi 我能';不使用接口编译类

Delphi 我能';不使用接口编译类,delphi,interface,Delphi,Interface,我试图创建一个实现接口的类,但出现以下错误: [dcc32 Error] dl_tPA_MailJournal.pas(10): E2291 Missing implementation of interface method IInterface.QueryInterface [dcc32 Error] dl_tPA_MailJournal.pas(10): E2291 Missing implementation of interface method IInterface._AddRef

我试图创建一个实现接口的类,但出现以下错误:

[dcc32 Error] dl_tPA_MailJournal.pas(10): E2291 Missing implementation of interface method IInterface.QueryInterface
[dcc32 Error] dl_tPA_MailJournal.pas(10): E2291 Missing implementation of interface method IInterface._AddRef
[dcc32 Error] dl_tPA_MailJournal.pas(10): E2291 Missing implementation of interface method IInterface._Release
[dcc32 Fatal Error] MainUnit.pas(8): F2063 Could not compile used unit 'dl_tPA_MailJournal.pas'
代码是:

unit dl_tPA_MailJournal;

interface

uses
  Windows,
  Generics.Collections,
  SysUtils,
  uInterfaces;

type
  TtPA_MailJournal = class(TObject, ITable)
  public
    function GetanQId: integer;
    procedure SetanQId(const Value: integer);
    function GetadDate: TDateTime;
    procedure SetadDate(const Value: TDateTime);

    function toList: TList<string>;

    constructor Create(aId : Integer; aDate : TDateTime);

  private
    property anQId : integer read GetanQId write SetanQId;
    property adDate : TDateTime read GetadDate write SetadDate;
end;

implementation

{ TtPA_MailJournal }

constructor TtPA_MailJournal.Create(aId : Integer; aDate : TDateTime);
begin
  SetanQId(aId);
  SetadDate(aDate);
end;

function TtPA_MailJournal.GetadDate: TDateTime;
begin
  Result := adDate;
end;

function TtPA_MailJournal.GetanQId: integer;
begin
  Result := anQId ;
end;

procedure TtPA_MailJournal.SetadDate(const Value: TDateTime);
begin
  adDate := Value;
end;

procedure TtPA_MailJournal.SetanQId(const Value: integer);
begin
  anQId := Value;
end;

function TtPA_MailJournal.toList: TList<string>;
var
  aListTable: TList<TtPA_MailJournal>;
  aTable: TtPA_MailJournal;
  aListString: TList<String>;
begin
  aTable.Create(1,now);
  aListTable.Add(aTable);
  aTable.Create(2,now);
  aListTable.Add(aTable);
  aListString.Add(aListTable.ToString);

  Result := aListString;
end;

end.
单位dl\u tPA\u邮件日志;
接口
使用
窗户,
非专利药,收藏,
SysUtils,
界面;
类型
TtPA_MailJournal=类(TObject,ITable)
公众的
函数GetanQId:integer;
过程SetanQId(常量值:整数);
函数GetadDate:TDateTime;
程序SetadDate(常量值:TDateTime);
功能列表:TList;
构造函数创建(aId:Integer;aDate:TDateTime);
私有的
属性anQId:整数读取GetanQId写入SetanQId;
属性adDate:TDateTime读取GetadDate写入SetadDate;
结束;
实施
{TtPA_MailJournal}
构造函数TtPA_MailJournal.Create(aId:Integer;aDate:TDateTime);
开始
SetanQId(援助);
SetadDate(aDate);
结束;
函数TtPA_MailJournal.GetadDate:TDateTime;
开始
结果:=adDate;
结束;
函数TtPA_MailJournal.GetanQId:整数;
开始
结果:=anQId;
结束;
程序TtPA_MailJournal.SetadDate(常量值:TDateTime);
开始
adDate:=值;
结束;
过程TtPA_MailJournal.SetanQId(常量值:整数);
开始
anQId:=值;
结束;
函数TtPA_MailJournal.toList:TList;
变量
aListTable:TList;
aTable:TtPA_MailJournal;
aListString:TList;
开始
创建(1,现在);
alistable.Add(aTable);
创建(2,现在);
alistable.Add(aTable);
添加(aListTable.ToString);
结果:=aListString;
结束;
结束。
界面为:

unit uInterfaces;

interface

uses
  Generics.Collections;

type
  ITable = Interface
    ['{6CED8DCE-9CC7-491F-8D93-996BE8E4D388}']
    function toList: TList<string>;
  end;

implementation

end.
单元接口;
接口
使用
仿制药。收藏;
类型
ITable=接口
[{6CED8DCE-9CC7-491F-8D93-996BE8E4D388}]
功能列表:TList;
结束;
实施
结束。

问题在于您使用
TObject
作为类的父对象。你应该改用

在Delphi中,每个接口都继承自
IInterface
,因此至少具有以下功能:

您必须实现这3个方法,要么自己实现,要么从包含这些方法的基础对象继承

由于继承自
TObject
,但未实现这3个方法,因此会出现编译错误。如果您阅读编译器错误,您将看到它实际上为您解释了这个省略

已经为您实现了这些方法。
实现的其他基本对象有:和。然而,这些都是特殊用途的车辆,只有当你真的知道你在做什么的时候才能使用

将类的定义更改为

TTPA_MailJournal = class(TInterfacedObject, ITable)
您的代码将被编译


有关更多信息,请参阅。

或者,根据使用位置的不同,您可以。