[Gambas-user] Answer to: "Way to tell if an object is a struct"
brian at westwoodsvcs.com
Thu Apr 6 08:26:07 CEST 2023
Yes but this does not differentiate a structure from a normal object
Brian G Wednesday, 05 April 2023, 02:22PM -07:00 from Jussi Lahtinen jussi.lahtinen at gmail.com :
>There is already TypeOf() function. And you can get the class with Object.Type().
>On Wed, Apr 5, 2023 at 7:05PM vuott--- via User < user at lists.gambas-basic.org> wrote:
>>On this thread
>>Brian G asked, if it were possible to know if an Object is a Structure.
>>In Gambas source file
>>the numbers of datatypes identifiers are listed.
>>Therefore, by knowing which number a declared variable belongs to, it is possible to know its data type.
>>I found a way to know, from the memory address of the variable it is necessary to go back 8 units. Deferencing the Pointer will give the identifier number of the data type of the variable, which consequently will have to be compared with the list above.
>>This is my simply code:
>>Public Struct Struttura
>> b As Byte
>> c As Short
>>Private id As Struct Struttura
>>Public Sub Main()
>>Dim p As Pointer
>>p = VarPtr(id)
>>Print "Gambas datatype identifier: "; Byte@(p - 8)
>>It should be noted that in the list of data-type identifier numbers, in particular, the data type Structure is NOT present.
>>It will be located and reported by my code as an "Object" (number: 16)
>>----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the User