编辑:
常数
字符串,因为它们共享相同的内存和相同的地址(所以我以前关于更好的RTTI的假设是错误的)。
所以可靠的方法是
type
TRecS = record
s: string;
end;
var
rec1, rec2: TRecS;
comparerS: IEqualityComparer<TRecS>;
cmp: IEqualityComparer<TRecS>;
res: boolean;
begin
rec1.s := 'const';
rec2.s := 'const';
comparerS := TEqualityComparer<TRecS>.default;
res := comparerS.equals(rec1, rec2);
Memo1.Lines.Add(boolToStr(res));
rec1.s := IntToStr(88);
rec2.s := IntToStr(88);
res := comparerS.equals(rec1, rec2);
Memo1.Lines.Add(boolToStr(res));
cmp := TEqualityComparer<TRecS>.Construct(
function(const Left, Right: TRecS): Boolean
begin
Result := Left.S = Right.S
end,
nil);
res := cmp.equals(rec1, rec2);
Memo1.Lines.Add(boolToStr(res));
-1 //denotes true
0
-1