What do you expect is the output?

What do you expect is the output?

var
  v: TValue;
begin
  v := 'Hello world';
  Writeln(v.IsType);
  Writeln(v.IsType);
  Writeln(v.IsType);
end;

When working on a fix for http://qc.embarcadero.com/wc/qcmain.aspx?d=107906 I noticed that IsType just calls TryCast and thus IsType returns true for any type it can convert to Variant.
http://qc.embarcadero.com/wc/qcmain.aspx?d=107906

Comments

  1. True, False, False.
    Given its implementation IsType should rather be named "IsCastableToType" or "IsCompatibleWithType"

    ReplyDelete
  2. I'm too lazy -- what is the output?

    ReplyDelete
  3. Nick Hodges True, False, True (!) because TryCast returns True when casting a compatible type to Variant (well, except Boolean as in the mentioned bug which is why I found that)

    ReplyDelete
  4. Marco Cantù XE4 has a "kind of" fix for the above mentioned bug (no exception anymore) but it does cast every enumeration to Int64 and puts that into the Variant.

    ReplyDelete

Post a Comment