-
Notifications
You must be signed in to change notification settings - Fork 7
TAny
Ivan Semenkov edited this page Oct 17, 2021
·
1 revision
The class TAny
describes a type-safe container for single value.
TAnyValue
is a wrapper for custom type.
uses
utils.any;
type
TAnyValue = class
end;
uses
utils.any;
type
{$IFDEF FPC}generic{$ENDIF} TAny<T> = class(TAnyValue)
end;
A new any value can be created by call its constructor.
constructor Create (AValue : T);
uses
utils.any;
type
TInteger = {$IFDEF FPC}specialize{$ENDIF} TAny<Integer>;
var
value : TAnyValue;
begin
value := TInteger.Create(5);
FreeAndNil(value);
end;
Return any value.
property Value : T;
uses
utils.any;
type
TInteger = {$IFDEF FPC}specialize{$ENDIF} TAny<Integer>;
var
value : TAnyValue;
begin
value := TInteger.Create(5);
writeln(TInteger(value).Value);
FreeAndNil(value);
end;