RAD Studio VCL Reference
|
System::Variant is a C++ implementation of the Delphi intrinsic type System::Variant.
Variant = class(TVarData);
class Variant : public TVarData;
The System::Variant type is capable of representing values that change type dynamically. Whereas a variable of any other type is statically bound to that type, a variable of the System::Variant type can assume values of differing types at run-time. The System::Variant type is most commonly used in situations where the actual type to be operated upon varies or is unknown at compile-time. While variants offer great flexibility, they also consume more memory than regular variables, and operations on variants are substantially slower than operations on statically typed values.
System::Variants can contain various numeric, string, Boolean, and date-time values. If COM is available (Windows only) variants can also contain OLE Automation objects. Finally, variants can contain arrays of any of the above types. The special System::Variant value Unassigned is used to indicate that a variant has not yet been assigned a value, and the special variant value Null is used to indicate unknown or missing data.
A variant can be constructed from the following data types:
WordBool
Byte
char *
wchar_t * const
Ole2::IDispatch* const (Windows only)
Ole2::IUnknown* const (Windows only)
In C++ code, variant arrays are usually created using a System::Variant constructor in conjunction with the OPENARRAY macro:
Variant V(OPENARRAY(int,(0,HighVal,0,HighVal)),varInteger);
You can also use the VarArrayCreate function, but that function is designed for use in Delphi code, and makes for complex C++ code.
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|