[Gambas-user] Iterating through a class

Arief Bayu Purwanto ariefbayu at ...626...
Tue Apr 8 09:01:03 CEST 2008


try this:
Dim hClass As Class = Class.Load("Class1")

On Sat, Apr 5, 2008 at 12:33 PM, richard terry <rterry at ...1822...> wrote:

> On Mon, 31 Mar 2008 12:32:48 am Benoit Minisini wrote:
> > On dimanche 30 mars 2008, richard terry wrote:
> > > Is it possible to interact through a class in code
> > > eg cMyclass
> > > public sWhatever as string
> > > public sNextThing as string
> > > public bSomething as boolean.
> > >
> > > ie can you  somehow printout the values contained in a class without
> > > specifically addressing them by name.
> > >
> > > Maybe a stupid question.
> > >
> > > Regards
> > >
> > > Richard T
> >
> > You can browse the public symbols of a class. Not the private ones, as
> they
> > do not exist anymore once the program is compiled, except for the
> debugger.
> >
> > To do that:
> >
> > DIM hObject AS Object = ... ' <- Your cMyClass instance
> > DIM hClass AS Class = Class["cMyClass"]
> >
> > FOR EACH SymbolName IN hClass.Symbols
> >   WITH hClass[SymbolName]
> >     IF .Kind = Class.Variable THEN
> >       PRINT .Name;; Object.GetProperty(hObject, .Name)
> >     ENDIF
> >   END WITH
> > NEXT
> >
> > I think that works. Otherwise you will tell me...
>
> Finally got around to trying this with no luck.  AS a simple example I put
> a
> button on the form and intended to load the names into a list (project
> supplied)
>
> There is no reference what SymbolName should be set to amongst other
> things. I
> tried:
>
>
> Public myclass As Class1
> Public Sub form_Open()
>
> myclass = New Class1
>
> End
> Public Sub Button1_Click()
>
> Dim SymbolName As String '????
> Dim hObject As Object = myclass
> Dim hClass As Class = Class["Class1"]  (dies here complaining it is not an
> object)
>
>
> For Each SymbolName In hClass.Symbols
>  With hClass[SymbolName]
>    If .Kind = Class.Variable Then
>      Print .Name;; Object.GetProperty(hObject, .Name)
>    Endif
>  End With
> Next
>
> End
>
> Any help appreciated.
>
> Richard
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Register now and save $200. Hurry, offer ends at 11:59 p.m.,
> Monday, April 7! Use priority code J8TLD2.
>
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>


-- 
Arief Bayu Purwanto
About : http://about.freelancer.web.id/
Blog : http://bayu.freelancer.web.id/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: classit-0.0.1.tar.gz
Type: application/x-gzip
Size: 8264 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20080408/cd3daf4d/attachment.bin>


More information about the User mailing list