加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 可以有两个具有相同名称的属性吗?

发布时间:2020-12-15 06:10:59 所属栏目:大数据 来源:网络整理
导读:是否可以有两个具有相同名称的属性? property Cell [Cl,Rw: Integer]: string read getCell write setCell;property Cell [ColName: string; Rw: Integer]: string read getCellByCol write setCellByCol; 嗯,我试过,编译器不会让我这样做,但也许有一个诀窍
是否可以有两个具有相同名称的属性?
property  Cell [Cl,Rw: Integer]: string   read getCell  write setCell;
property  Cell [ColName: string; Rw: Integer]: string read getCellByCol write setCellByCol;

嗯,我试过,编译器不会让我这样做,但也许有一个诀窍?

解决方法

不,但是再次:是…排序…
function    getP1(Cl,Rw : integer) : string;
procedure   setP1(C1,Rw : integer ; const s : string);
function    getP2(const Cl : string ; Rw : integer) : string;
procedure   setP2(const C1 : string ; Rw : integer ; const s : string);
property    P1[Cl,Rw : integer] : string read getP1 write setP1; default;
property    P1[const Cl : string ; Rw : integer] : string read getP2 write setP2; default;

诀窍是将属性命名为相同,并使用“default”子句标记.然后,您可以使用各种参数访问相同的属性名称:

P1['k',1]:=P1[2,1];
P1[2,1]:=P1['k',1];

编译好,不知道这是否被非常支持,或者还有其他一些问题,但是它编译得很好,调用正确的getter / setter(在Delphi 2010中测试).

这当然只有在您没有为您的类使用默认属性时才起作用,因为我能够使其工作的唯一方法是通过默认子句.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读