Name

ChangeAnyProc Variable

Syntax

var ChangeAnyProc: Pointer;

procedure ChangeAny(var V: Variant);
ChangeAnyProc := @ChangeAny;

Description

The ChangeAnyProc procedure changes a varAny Variant value to a Variant type that Delphi can use. A varAny value represents an opaque type Delphi cannot work with other than to assign and pass to subroutines.

The default value of ChangeAnyProc is a procedure that raises runtime error 15 (EVariantError).

Tips and Tricks

The CorbaObj unit sets this variable to point to a procedure that supports CORBA’s Any type. If you are not using CORBA, you can use varAny values for your own purposes.

Example

Suppose you want to use Variants in an application, but you need to store Int64 values. Delphi’s Variant does not support the Int64 type, but you can use varAny to store Int64 values. When Delphi needs a concrete value, the ChangeAnyProc procedure converts the Int64 to a string, which Delphi understands how to use. The VAny field is a pointer, so the SetVarInt64 procedure allocates dynamic memory to store the Int64 value, and saves the pointer in the Variant. The ClearAnyProc procedure frees the memory when Delphi is done using the Variant value.

// Change a varAny Int64 value to a known Variant type, specifically
// a string.
procedure ChangeVarInt64(var V: Variant);
var
  Value: Int64;
begin
  if TVarData(V).VType = varAny then
  begin
    Value := PInt64(TVarData(V).VAny)^;
    V := IntToStr(Value);
  end;
end;
...
ChangeAnyProc := @ChangeVarInt64;

See Also

ClearAnyProc ...

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.