I have the following class
:
TTest = class
private
FId: Integer;
FSecField: Integer;
FThirdField: Integer;
public
constructor Create(AId, ASecField, AThirdField: Integer);
// .....
end;
Then I create a TObjectDictionary
like this:
procedure TMainForm.btnTestClick(Sender: TObject);
var
TestDict: TObjectDictionary<TTest, string>;
Instance: TTest;
begin
TestDict := TObjectDictionary<TTest, string>.Create([doOwnsKeys]);
try
TestDict.Add(TTest.Create(1, 1, 1), '');
if TestDict.ContainsKey(TTest.Create(1, 1, 1)) then
ShowMessage('Match found')
else
ShowMessage('Match not found');
Instance := TTest.Create(1, 1, 1);
TestDict.Add(Instance, 'str');
if TestDict.ContainsKey(Instance) then
ShowMessage('Match found')
else
ShowMessage('Match not found');
finally
TestDict.Free;
end;
end;
The result is: "Match not found", "Match found". What should I do in order to compare the values of fields of each key but not their addresses?