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,860 other subscribers

Delphi: Variant versus OleVariant (via: RAD Studio API Documentation)

Posted by jpluimers on 2014/07/16

I used to forget about the difference between Variant and OleVariant, and used them like this:

Use OleVariants for OLE, and Variants for non OLE.

There is no need to manually clear them.

Luckily I was right, as the differences are documented in the Delphi on-line help at OLE-compatible Variant type (the oldest I could find was the Delphi 2010 OleVariant documentation):

OleVariant is an OLE-compatible Variant. The main difference between Variant and OleVariant is that Variant can contain data types that only the current application knows what to do with. OleVariant can only contain data types defined as compatible with OLE Automation, which means that contained data types can be passed between programs or across the network without worrying about whether the other end will know how to handle the data.

When you assign a Variant that contains custom data (such as a Delphi string, or one of the new custom variant types) to an OleVariant, the runtime library tries to convert the Variant into one of the OleVariant standard data types (such as a Delphi string converts to an OLE BSTR string). For example, if a Variant containing an AnsiString is assigned to an OleVariant, the AnsiString becomes a WideString. The same is true when passing a Variant to an OleVariant function parameter.

–jeroen

via: System.OleVariant – RAD Studio API Documentation.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.