TPublishableVariantType is the base class for new data types for Variants that have properties and methods. TPublishableVariantType descendants do not represent the Variants themselves. Rather, they act as utility classes that the custom Variants call on to perform their operations. TPublishableVariantType adds to its ancestor's ability to implement properties and methods on Variants of the custom type by automatically implementing all published properties of the object it uses to store its data.
Note: To create a
Variant type that descends from TPublishableVariantType,
Note: 2.
Write a method that creates instances of your custom
Variant. This fills in the
Variant's data as defined in step 1.
Note: 3. Declare a class that descends from TPublishableVariantType.
Note: 4. Override the
GetInstance method to return the object that stores the custom
Variant's data.
Note: 5. Implement all other required behavior (including type conversion rules) in the new class. This involves overriding the appropriate virtual methods (typically DoFunction, DoProcedure, BinaryOp, UnaryOp, CompareOp or Compare, Cast, CastTo, Clear,
Copy, IsClear, LeftPromotion, and RightPromotion).
Note: 6. In the initialization section of the unit that defines your TPublishableVariantType descendant, create an instance of your class. When you instantiate your object, it automatically registers itself with the
Variant-handling system so that the new
Variant type is enabled.
Note: 7. In the finalization section of the unit that defines your TPublishableVariantType descendant, free the instance of your class. This automatically unregisters the
Variant type.
Note: For an example, see the
VarCmplx (Windows) or
FMTBcd (Linux) unit, which implements a custom
Variant type for complex (Windows) or binary-coded decimal (Linux) numbers.
Note: Do not create your own custom
Variant types in C++. They are only supported in Delphi.