Results 1 to 5 of 5

Thread: about properties

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    about properties

    i have these property in usercontrol:

    Code:
    Public Property Get StripsActivate() As Boolean
        StripsActivate = Strip.Activate
    End Property
    
    Public Property Let StripsActivate(ByVal vNewValue As Boolean)
        Strip.Activate = vNewValue
        If Strip.Activate = True Then
            Strip.ActualSubImage = 1
            lngActualSubImage = 1
            lngTotalSubImages = Strip.ImagesColumn * Strip.ImagesLine
            Call UpgradeSubimages
            tmrAnimation.Enabled = True
            tmrAnimation.Enabled = Ambient.UserMode
        Else
            tmrAnimation.Enabled = False
            lngActualSubImage = 0
        End If
        PropertyChanged "StripsActivate"
    End Property
    and i have these in:

    Code:
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
        If StripsActivate = True Then
            lngActualSubImage = PropBag.ReadProperty("ActualSubImage", 1)
            Strip.ActualSubImage = 1
            lngTotalSubImages = Strip.ImagesColumn * Strip.ImagesLine
            Call UpgradeSubimages
            UserControl.Picture = PicAnimation(1).Image
            Call Transparent
            tmrAnimation.Enabled = True
            tmrAnimation.Enabled = Ambient.UserMode
        Else
            lngActualSubImage = PropBag.ReadProperty("ActualSubImage", 0)
            lngTotalSubImages = PicAnimation.Count
            UserControl.Picture = PicAnimation(0).Image
            Call Transparent
        End If
    end sub
    and i have the same in writeproperties usercontrol event.
    my question is why i must repeat 3 times the code for a persistence property?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: about properties

    if my question is confuse, just tell me...
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: about properties

    these property is to be used in IDE property window. but did i need repeat/call the code 3 times?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: about properties

    Yes you can cut these down into 1 method, and both involve using a collection of settings to be retreived or set - otherwise known as a propertybag.

    1) You could make a note of the differences between them, and implement these as individual flagged boolean variables stored within a propertybag. I.e. taking this different line:
    Code:
    Call Transparent
    You could then create a PropertyBag setting of CallTransparentMethod. By accepting a propertybag object as an argument in your property, and evaluating whether this setting had a true or false value, your property/code could then choose to run or skip that line of code.

    2) You can have an Enum/Enumeration of the different setting applications possible. I.e.
    Code:
    Private Enum StripsActivateSettingType
        WithTransparency = 0
        WithoutTransparency = 1
    End Enum
    You could then code this into a sub procedure which accepts both a property bag argument of settings to read/write, and a second argument of this enum type. If the Enum value is 1, you can execute the code as in your 2nd posted code there, if the value of the passed in Enum is 2, then you can execute the code similar to the 3rd code sample you posted (which includes the above Call Transparent line).
    Last edited by alex_read; Jun 12th, 2008 at 03:30 PM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: about properties

    Quote Originally Posted by alex_read
    Yes you can cut these down into 1 method, and both involve using a collection of settings to be retreived or set - otherwise known as a propertybag.

    1) You could make a note of the differences between them, and implement these as individual flagged boolean variables stored within a propertybag. I.e. taking this different line:
    Code:
    Call Transparent
    You could then create a PropertyBag setting of CallTransparentMethod. By accepting a propertybag object as an argument in your property, and evaluating whether this setting had a true or false value, your property/code could then choose to run or skip that line of code.

    2) You can have an Enum/Enumeration of the different setting applications possible. I.e.
    Code:
    Private Enum StripsActivateSettingType
        WithTransparency = 0
        WithoutTransparency = 1
    End Enum
    You could then code this into a sub procedure which accepts both a property bag argument of settings to read/write, and a second argument of this enum type. If the Enum value is 1, you can execute the code as in your 2nd posted code there, if the value of the passed in Enum is 2, then you can execute the code similar to the 3rd code sample you posted (which includes the above Call Transparent line).
    i'm sorry but i wasn't talking about transparent procedure but entire property...
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

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



Click Here to Expand Forum to Full Width