The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,364 other followers

Why you should try to avoid using Variant operations in Delphi

Posted by jpluimers on 2018/04/17

[WayBackDelphi “WAT?!” of the day: var v1, v2: Variant; begin v1 := True; v2 := True… shows some interesting code.

The [WayBackVariant Types (Delphi) – RAD Studio: Variant Type Conversions (and the decimal point/comma handling or rounding issues not documented there) usually kill you and are the most important reason to avoid Variant operations in Delphi.

–jeroen

5 Responses to “Why you should try to avoid using Variant operations in Delphi”

  1. mesignapk said

    I wanna learn Coding. From where I should start?? I am beginner and currently running a blog https://geekolive.com

  2. Arnaud Bouchez said

    In fact, it is as expected. For variants, boolean are mapped as a COM Boolean, i.e. WordBool and not a pascal/Delphi boolean, with 0 or $ffff as values.
    So, with sign extension, the result is as expected.
    And note that FPC will give the very same results (at least in Delphi compatibility mode).

    • jpluimers said

      Indeed. In the Variant documentation, COM is only mentioned once and OleVeriant is only at the end. It should be stressed that the stock conversions are all involving COM data types which can behave quite differently from Delphi built-in types.

      • Arnaud Bouchez said

        To be accurate, WordBool is a true Delphi built-in type, just as native than Boolean, but in practice only used with COM/variants… :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

 
%d bloggers like this: