【发布时间】:2015-11-06 03:39:21
【问题描述】:
我是接口方面的新手。我google了很多,但我不知道在以下情况下该怎么办。
我创建了多个接口,它们相互使用:
IPart = interface(IInterface)
Function getName: string;
procedure setName(aValue: string)
property Name: string read getName write setname;
end;
IOfferLine= interface(iInterface)
Function getPart: IPart;
function getAmount: double;
procedure setPart(aPart: IPart);
procedure setAmount(value: double);
property Amount: double read getAmount write setAmount;
property Part: IPart read GetPart write setPart;
end;
IOffer= interface(iInterface)
function getOffLines: tList<IOfferline>;
procedure setOffLines(aList: tList<IOfferline>);
property OffLines: tList<IOfferlines> read getOffLines write setOfflines;
end;
现在我想实现这些接口。
TPart = class(TInterfacedObject, IPart)
private
_Name: string;
function getName: string;
procedure setName(aValue: string);
public
property Name: string read getName write setName;
end;
TOfferLine = class(TInterfacedObject, IOfferLine)
private
_amount: double;
_part: TPart;
function getAmount: double;
function getPart: tPart;
procedure setAmount(aValue: double);
procedure setPart(aPart: TPart);
public
property Amount: double read getAmount write setAmount;
property Part: TPart read GetPart write SetPart;
end;
TOffer = class(TInterfacedObject, IOffer)
private
_OfferLines: tList<TOfferline>;
function getOffLines: tList<tOfferline>;
procedure setOffLines(aList: tList<tOfferline>);
public
property offLines: tList<TOfferline> read getOffLines write setOffLines;
end;
我已经添加了实现。
function TOfferLine.getPart: tPart;
begin
result := _part;
end;
但我仍然得到“缺少接口方法 IOfferline.GetPart 的实现;”
我不知道为什么。
【问题讨论】:
-
您显示的代码无法编译并且相当混乱。这表明缺乏清晰度和对细节的关注。这里也没有明确和直接的问题。我认为您可能需要更加专注地重新编写这个问题。
-
@DavidHeffernan,我编辑了这个问题。你能解释一下为什么这段代码很乱吗?
-
代码仍然无法编译。它仍然以难以阅读的方式缩进。仍然没有具体的问题。看起来你在走路之前就想跑。
-
所有类型声明中都缺少
end关键字。 -
当然……你在接口中的GetPart是IPart而不是TPart!!
标签: delphi interface interface-implementation