uses System.SysUtils, System.Variants;
function DynamicReturn(I: Integer): Variant;
begin
case I of
1: Result := 3.14;
2: Result := 'any';
3: Result := True;
else
//Null is the empty Variant
Result := Null;
end;
end;
var
Pi, S, B, Nothing: Variant;
begin
Pi := DynamicReturn(1);
//Pi is 3.14
S := DynamicReturn(2);
//S is 'any'
B := DynamicReturn(3);
//B is True
Nothing := DynamicReturn(4);
WriteLn(VarToStr(Pi), '; ', VarToStr(S),
'; ', VarToStr(B));
//3.14; any; True
WriteLn('isNull is ',
VarIsNull(Nothing));
//isNull is TRUE
end.