Using Delphi Rio 10.3.3 I created a record with two fields, an equality comparison operator. One of the fields is an enumerator.
When I create two variables of this type without 'building them' and compare with another, if the variable 'inline', the comparison returns as equals. However, if the variable is by the traditional way, the comparison returns False
. The enumerator field is not initializing when it is declared in traditional way.
type
TPropT = (ptYes, ptNo, ptMaybe);
MyConfuseRecord = record
var
Fprop: String;
FpropT: TPropT;
constructor Create(_fieldName: string; aPropT: TPropT = ptMaybe);
class operator Equal(_aLeft, _aRight: MyConfuseRecord): Boolean;
class operator NotEqual(_aLeft, _aRight: MyConfuseRecord): Boolean;
end;
...
constructor MyConfuseRecord.Create(_fieldName: string; aPropT: TPropT);
begin
Fprop := _fieldName;
FpropT := aPropT;
end;
class operator MyConfuseRecord.Equal(_aLeft, _aRight: MyConfuseRecord): Boolean;
var
Comparer: IEqualityComparer<string>;
begin
Comparer := TEqualityComparer<string>.Default;
Result := (Comparer.Equals(_aLeft.Fprop, _aRight.Fprop)) and (_aLeft.FpropT = _aRight.FpropT);
end;
class operator MyConfuseRecord.NotEqual(_aLeft, _aRight: MyConfuseRecord): Boolean;
begin
Result := not (_aLeft = _aRight);
end;
... Testing in diferent ways
procedure CompareMyRecords_Inline;
var
Rs: Boolean;
begin
var mRec1: MyConfuseRecord;
var mRec2: MyConfuseRecord;
Rs := mRec1 = mRec2; //True (mRec1.FPropT is everytime ZERO)
OutputDebugString(Pchar('Result (Inline) '+ BooltoStr(Rs, True) + ' | value = ' + Integer(mRec1.FPropT).ToString ) );
end;
procedure CompareMyRecords_Normal;
var
mRec1, mRec2 : MyConfuseRecord;
Rs: Boolean;
begin
Rs := mRec1 = mRec2; //False
OutputDebugString(Pchar('Result1 (normal) '+ BooltoStr(Rs, True) + ' | value1 = ' + Integer(mRec1.FPropT).ToString + ' value 2 = ' + Integer(mRec2.FPropT).ToString ));
end;
Is this an inconsistency in this version of Delphi?
ps: I read this post and I didn't come to a conclusion.