[Gambas-user] Answer to: "Way to tell if an object is a struct"

Brian G brian at westwoodsvcs.com
Fri Apr 7 15:29:22 CEST 2023


It relates to how an object is written by the write instruction. And knowing what will be written into a stream. Gambas objects and gambas structures have very different formats when written to a stream.
Sometimes one needs to know which it is.
--
Thanks
Brian G Thursday, 06 April 2023, 04:12PM -07:00 from Jussi Lahtinen  jussi.lahtinen at gmail.com :

>I understand that, but knowing the name allows you to write a function that gives you what you want.
>
>Jussi
>
>On Fri, Apr 7, 2023 at 1:15AM vuott--- via User < user at lists.gambas-basic.org> wrote:
>>Hi Jussi,
>>it seems to me that Brian G was  not interested in knowing the  name (label) of the Structure, but that the instance of the Structure was a " Structure " Object .
>>
>>
>>
>>6 apr 2023, 23:39 da  jussi.lahtinen at gmail.com :
>>>But if TypeOf() tells it is an object, then can't you get the structure name with Object.Type()?
>>>
>>>Jussi
>>>
>>>On Thu, Apr 6, 2023 at 9:33AM Brian G < brian at westwoodsvcs.com> wrote:
>>>>Yes but this does not differentiate a structure from a normal object
>>>>--
>>>>Thanks
>>>>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().
>>>>>
>>>>>Jussi
>>>>>
>>>>>On Wed, Apr 5, 2023 at 7:05PM vuott--- via User < user at lists.gambas-basic.org> wrote:
>>>>>>On this thread
>>>>>>    https://lists.gambas-basic.org/pipermail/user/2023-March/078862.html
>>>>>>Brian G asked, if it were possible to know if an Object is a Structure.
>>>>>>In Gambas source file
>>>>>>   /home/[USER]/gambasdevel/main/share/gambas.h
>>>>>>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:
>>>>>>
>>>>>>[code]
>>>>>>Public Struct Struttura
>>>>>>  b As Byte
>>>>>>  c As Short
>>>>>>End Struct
>>>>>>
>>>>>>Private id As Struct Struttura
>>>>>>
>>>>>>
>>>>>>Public Sub Main()
>>>>>>
>>>>>>Dim p As Pointer
>>>>>>
>>>>>>p = VarPtr(id)
>>>>>>
>>>>>>Print "Gambas datatype identifier: "; Byte@(p - 8)
>>>>>>
>>>>>>End
>>>>>>[/code]
>>>>>>
>>>>>>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 ]----
>>>>
>>>>----[  http://gambaswiki.org/wiki/doc/netiquette ]----
>>
>>
>>----[  http://gambaswiki.org/wiki/doc/netiquette ]----
>
>----[  http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230407/1ef2c5d0/attachment.htm>


More information about the User mailing list