Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Language/Variants    [ Add a report in this area ]  
Report #:  100806   Status: Open
Equality comparison between Variants wrong results
Project:  Delphi Build #:  16.0.4316.44803
Version:    16.0 Submitted By:   Tommaso Ercole
Report Type:  Minor failure / Design problem Date Reported:  11/7/2011 1:43:27 AM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   288669
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 10
Description
Comparison between different types wrapped inside Variants gives exceptions instead of False.
Steps to Reproduce:
Compile the attached project, should return two times PASSED, is returing two times FAILED.

-----------------
program VariantEquality;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  Generics.Defaults,
  System.SysUtils;

var
  A,
  B: Variant;

begin
  Write('VariantEquality, 1: ');
  try
    A:= '';
    B:= StrToDateTime('22/12/2012');
    if A = B then
      Writeln('FAILED')
    else
      Writeln('PASSED');

  except
    Writeln('FAILED');

  end;
  Write('VariantEquality, 2: ');
  try
    A:= '';
    B:= StrToDateTime('22/12/2012');
    if TEqualityComparer<Variant>.Default.Equals( A, B ) then
      Writeln('FAILED')
    else
      Writeln('PASSED');

  except
    Writeln('FAILED');

  end;
end.
-----------------
Workarounds
try except around every single comparison
Attachment
100806.zip
Comments

None

Server Response from: ETNACODE01