It seems that one, in my opinion mandatory method is missing from TValue; TValue.Equals(TValue).
So whats a fast and decent way of comparing 2 TValues, preferably without the use of TValue.ToString(), which allows false matches between variants, records, etc.
Delphi-Mocks presents two functions :
function CompareValue(const Left,Right : TValue): Integer;
function SameValue(const Left, Right: TValue): Boolean;
With the record helper for TValue you can also do TValue.Equals(TValue);
Licensed under Apache terms and under permission by Stefan Glienke.
Here is the original source by Stefan : delphisorcery.
If you need to extend the functionality for variants, add:
function TValueHelper.IsVariant: Boolean;
begin
Result := TypeInfo = System.TypeInfo(Variant);
end;
and insert
if Left.IsVariant and Right.IsVariant then
begin
Result := Left.AsVariant = Right.AsVariant;
end else
after the isString comparison in the SameValue
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With