RAD Studio |  |

Implementing Unary Operations
See Also
Collapse All

To allow the custom variant type to work with standard unary operators ( -, not), you must override the UnaryOp method. UnaryOp has two parameters: the value of the operand and the operator. Implement this method to perform the operation and return the result using the same variable that contained the operand.

For example, the following UnaryOp method comes from the TComplexVariantType defined in the VarCmplx unit:

Copy Code

    procedure TComplexVariantType.UnaryOp(var Right: TVarData; const Operator: TVarOp);
    begin
    if Right.VType = VarType then
    case Operator of
    opNegate:
    TComplexVarData(Right).VComplex.DoNegate;
    else
    RaiseInvalidOp;
    end
    else
    RaiseInvalidOp;
    end;

Note that for the logical not operator, which does not make sense for complex values, this method calls RaiseInvalidOp to cause a runtime error.

See Also

Implementing Binary Operations

Implementing Comparison Operations

Enabling Casting

Copying and Clearing Custom Variants

Using the TCustomVariantType Descendant

Loading and Saving Custom Variant Values

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!