首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >特性替代

特性替代
EN

Stack Overflow用户
提问于 2009-12-18 02:46:03
回答 1查看 2.9K关注 0票数 2

我有一个从TParent派生的类TChild。TParent有一个属性MyProp,它读取和设置数组中的一些值。当然,这个属性是由TChild继承的,但是我想在孩子的属性中添加一些额外的处理。下面的代码更好地解释了我想要做的事情,但它不起作用。我如何实现它?

代码语言:javascript
复制
TParent = class...
 private
   function  getStuff(index: integer): integer; virtual;
   procedure setStuff(index: integer; value: integer); virtual;
 public
   property MyProp[index: integer] read GetStuff write SetStuff
 end;

TChild = class...
 private
   procedure setStuff(index: integer; value: integer); override;
   function  getStuff(index: integer): integer; override;
 public
   property MyProp[index: integer] read GetStuff write SetStuff
 end;

procedure TChild.setStuff(value: integer);
begin
 inherited;      //  <-- execute parent 's code and
 DoMoreStuff;    //  <-- do some extra suff
end;

function TChild.getStuff;
begin
 result:= inherited;   <---- problem was here   
end;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-12-18 02:55:28

解决了。子函数实现错误。基本上,这些代码是有效的。解决方案是:

代码语言:javascript
复制
Result := inherited getStuff(Index);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1923747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档