Use Object as Variant, but how to tell if it is a dynamic array?

Island/Windows, Visual Studio 2019

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

Try something like this:

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.

Wondering if the bets would be if we implement an actual Variant (in Delphi RTL, probably)? @Diego_Navarro, what do you think?

@mh
If I may - I would suggest something like Delphi TValue
But so far it seems Object is good enough to do does what I what

Remind me what that does again? iirc someone brought this dup before, a year or so back, but i forgot the details.

As far as I remember (it’s quite a long time since I have used Delphi … :crazy_face: ) 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.

http://docwiki.embarcadero.com/Libraries/XE2/en/System.Rtti.TValue

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.

1 Like

I’ll have a deeper look tomorrow. thanx!