有没有可能有两个具有相同名称的属性?
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中测试过)。
当然,这仅适用于您的类尚未使用默认属性的情况,因为我唯一能够使其起作用的方法是通过default子句。
TDictionary<T>
。 - asd-tm
variant
或TField
类型的参数中坚持一种方法,在方法本身中确定实际传递的类型。 - Lieven Keersmaekersproperty Cell[Column:ColumnRec; Row: Integer]
- Sir Rufo