I use Object, as a replacement for Delphi’s Variant (or TValue container). And I have the following code:
var arr1: array of Integer := [0, 1, 2, 3, 4];
var arr2: array of Boolean := [true, false, true, true, true];
var i: Integer := 5;
var o1: Object := arr1;
var o2: Object := arr2;
var o3: Object := i;
Now, from o1, o2, o3, how can I tell the contained dynamic array type? Object.GetType doesn’t seem to provide a way to check IsDynamicArray? What would be the best way to check custome types? @mh@ck
var gggt := o1.GetType;
writeLN(gggt.BaseType = typeOf(&Array)); // base type for arrays is RemObjects.Elements.System.&Array.
writeLn(gggt.GenericArguments.First().Name); << element type.
As far as I remember (it’s quite a long time since I have used Delphi … ) TValue is something from the RTTI and so something similar like the .NET Reflection, but not as nice.
Variant in contrary is something like a specialized dynamicObject (in .NET terms).
TValue is a general container for value. It itself is a record. It is under System.Rtti, but I found it very useful … as a general container for value.
It seems to me … RemObject’s Object is, already in some way, like TValue to be a container of a value of a specific type, except just missing some utility helper methods. Variant is slow.
Yeah. That was me…
TValue is mostly for transporting values, in a general way. it does NOT do conversion like Variant. So in many cases, I found TValue is more light-weight and handy and preferable than Variant.