Hi all
Hi all,
I Have two records i want to compare their references (something similar to .NET referenceequals), my approach seems to fail, ( I get access violations)
my function below tries to convert my record to an object so that I can use TObject 'equals' helper to compare their object Instances.
class function TIntX.MakeTIntXRecordAnObject(Const anInstance: TIntX): TObject;
begin
Move(anInstance, result, SizeOf(anInstance));
end;
hovering over 'result' in the debugger after executing the move command indicates that 'result' is empty.
also tried casting " result := TObject(anInstance);" but it did not compile with error saying invalid typecast.
please how do I do this, to be compatible with both 32bit and 64bits.
Thanks.
I Have two records i want to compare their references (something similar to .NET referenceequals), my approach seems to fail, ( I get access violations)
my function below tries to convert my record to an object so that I can use TObject 'equals' helper to compare their object Instances.
class function TIntX.MakeTIntXRecordAnObject(Const anInstance: TIntX): TObject;
begin
Move(anInstance, result, SizeOf(anInstance));
end;
hovering over 'result' in the debugger after executing the move command indicates that 'result' is empty.
also tried casting " result := TObject(anInstance);" but it did not compile with error saying invalid typecast.
please how do I do this, to be compatible with both 32bit and 64bits.
Thanks.
@ Chris Rolliston, I guess I will roll out my own type specific comparison
ReplyDeletethanks
Just write an operator overload for Equal and then you can write if r1 = r2 then
ReplyDeleteSee http://docwiki.embarcadero.com/RADStudio/XE8/en/Operator_Overloading_(Delphi)
Or write an IsEqualTo(const other): boolean. If you are managing lots of different records i guess RTTI could help. Steep curve but nice when it's finished.
ReplyDelete