Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jan 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Determining properties (VB 6.0)

    Hi Folks: I am trying to write a program where I have to maintain a file that will save the current state of a global "CurrentState" object. The Current State object has several collections of other objects (along with singleton primitives and objects) each of which may contain other collections of other objects (or primitives) and/or singleton objects and/or primitive properties.

    Now, for each object type I have I can create a "WriteToStateFile" method that will write each primitive property value of the object to the global statefile, but I want a method that does this without knowing what the object's properties are. i.e. imagine I have two methods - one called WriteObjectToStateFile and another called WritePrimitiveToStateFile and I have some Object called obj which I know may contain both objects and primitives. I want to know how to go through all the properties of obj, determine which are Objects in their own right and which are primitives, then call the appropriate Write method based upon that determination. My problem is knowing how many properties my original obj has and how to access them in a generic manner.

    Class SomeClass
    aMemberClass as AnotherClass
    aStringPrimitive as String
    anIntPrimitive as Integer
    '''''
    Define sets/gets/lets blah blah

    End Class

    Public Sub WriteToStateFile (Obj As Object)

    Dim var, i as Integer

    Set var = New Obj.CollectionOfProperties 'I wish this existed for any user defined class (could i define it somehow?)

    For i = 1 to var.Count 'Then I could do this
    if IsObject(var(i)) then
    WriteToStateFile var(i) 'Note the recursive call
    else
    WritePrimitiveToStateFile var(i)
    end if
    Next i
    End Sub

    Private Sub WritePrimitiveToStateFile (prim as Variant)

    OpenStateFileForAppend
    'if necessary do a select on typeof prim to determine the primitive type and then...
    StateFile.AppendLine prim
    StateFile.Close

    End Sub

    SO my problem is - is there some means of getting this Obj.listOfProperties in a generic manner rather than going through a TypeOf Obj scenario where I still end up writing all the object type specific routines.

    (and forgive me if i seem to be asking the inane q's of a newbie...since i am not a pro)

    regards,
    Lup

    [img]/forums/images/smilies/smile.gif[/img]

  2. #2
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining properties (VB 6.0)

    Do a search on PlanetSourceCode.com, in the VB section for Properties Property. It is an add-in for VB that I wrote. What it does, is go through the code for each class you select, and then it builds a properties property. You can then 'loop' through the properties in your classes with a For Next statement. You are able to retrieve/set the properties value, and retrieve the properties name.

    I also have this add-in on my site www.wolfwares.com, but it is down right now, though it should be up anytime soon.

  3. #3
    New Lounger
    Join Date
    Jan 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining properties (VB 6.0)

    Thanks a lot! Will check out your control - probably save myself some headaches since I have at least 20 classes and collections thereof to write this danged state saving for...

    best regards,
    Lup

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •