[Gambas-user] class enumeration help

Benoit Minisini gambas at ...1...
Thu May 1 09:46:20 CEST 2008


On mercredi 30 avril 2008, Robin Thompson wrote:
> Hi,
>
> As part of a project I would like to enumerate symbols of user defined
> class.
>
> code:
> tst1.class
> ' Gambas class file
> PUBLIC aan AS Integer
> PUBLIC ban AS String
> PUBLIC can AS Float
>
> PUBLIC SUB Main()
> DIM test1 AS NEW tst1
> DIM st AS String
>
> test1.aan = 1
> test1.ban = "hello"
> test1.can = 1.1
>
> PRINT #File.out, "aan: " & test1.aan
> PRINT #File.out, "ban: " & test1.ban
> PRINT #File.out, "can: " & test1.can
>
> WITH Object.Class(test1)
> FOR EACH st IN .Symbols
> PRINT #File.out, st & ": " & Object.Class(test1)[st].Value
> NEXT
> END WITH
>
> END
>
> Obviously (hopefully!) the output i would expect is:
> aan: 1
> ban: hello
> can: 1.1
> aan: 1
> ban: hello
> can: 1.1
>
> However i am in fact getting this:
>
> aan: 1
> ban: hello
> can: 1.1
> aan:
> ban:
> can:
>
> Where am I going wrong?
>
> Thanks for your help,
>
> RT
>

The value property returns the value of the symbol when it is a constant, not 
the value at runtime. To get the runtime value, use Object.GetProperty() 
*and* Gambas 3.

Regards,

-- 
Benoit Minisini




More information about the User mailing list