Link to home
Start Free TrialLog in
Avatar of TungVan
TungVan

asked on

Set keyword


Hi,

I have a CButton class.

I created an instance of it called                         Dim mButton as CButton

I have a Temporary button object called             Dim mTemp as CButton

I also have a AddButton function that takes 2 arguments: 1 flag, and 1 Button object


------------------------------------------------------------------------------------------------------------------------
AddButton False, mTemp

Public Sub AddButton(ByVal NewButtonFlag As Boolean, Optional ByVal lButton As Object)

    Dim lButtonIndex As Integer
    lButtonIndex = myMapForm!cmdButton.UBound + 1
    ReDim Preserve mButtonArray(lButtonIndex)
   
    'Flag = true means that we create a new button and put it into the array
    If NewButtonFlag = True Then
        Dim myButton As CButton
        Set myButton = New CButton
        Set mButtonArray(lButtonIndex) = myButton
        Set myButton = Nothing
       
    'Flag = false means that we copied the button in the function parameter into the array
    ElseIf NewButtonFlag = False Then
        Set mButtonArray(lButtonIndex) = lButton
   
    Else
        'do nothing
       
    End If
   
    Load myMapForm!cmdButton(lButtonIndex)
    myMapForm!cmdButton(lButtonIndex).Visible = True
    myMapForm!cmdButton(lButtonIndex).Left = 0
    myMapForm!cmdButton(lButtonIndex).Top = 0
    myMapForm!cmdButton(lButtonIndex).ZOrder
    PaintButton (lButtonIndex)



End Sub
------------------------------------------------------------------------------------------------------------------------

But Set keyword set the pointer of mButtonArray(lButtonIndex) to lButton, and in this case, is mTemp.

Everytime I modify mTemp properties, it also set the properties of mButtonArray(lButtonIndex)....since it copies the reference or pointer...

But that's not I wish to have. I just want to copy properties of mTemp to mButtonArray(lButtonIndex)...but I want them to be independent...If I set the properties of mTemp, I don't want it to automatically set the properties of mButtonArray(lButtonIndex)

Do you have a idea for that? Except copying manually...like this
------------------------------------------------------------------------------------------------------------------------
    Dim lButtonIndex As Integer
    lButtonIndex = myMapForm!cmdButton.UBound + 1
    ReDim Preserve mButtonArray(lButtonIndex)
    Dim myButton As CButton
   
    'Flag = true means that we create a new button and put it into the array
    If NewButtonFlag = True Then
        Set myButton = New CButton
        Set mButtonArray(lButtonIndex) = myButton
        Set myButton = Nothing
       
    'Flag = false means that we copied the button in the function parameter into the array
    ElseIf NewButtonFlag = False Then
        Set myButton = New CButton
        myButton.ButtonType = lButton.ButtonType
        myButton.CControl_ControlLabel = lButton.CControl_ControlLabel
        Set mButtonArray(lButtonIndex) = myButton
        Set myButton = Nothing
------------------------------------------------------------------------------------------------------------------------
This works ok...But i have to copy each attribute manually one at a time....It's a bit tedious....Is there a better way to do it?


Thanks

ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial