CD-Softy
asked on
Passing variables in ActiveX DLL with form
I would like to know if there is a cleaner of way of doing this...
I have an ActiveX (DLL) project that contains a Public Class, a Form and a module. When the class is instantiated, one of the methods of the class is to show the Form, which acts basically as a visual interface to set the properties of the class. Now it's not that hard to access the properties of the class from the Form, but the only way I can see to set the properties in the class from the Form is to use public duplicate variables in a module, which is then accessable from the class. To me, this kind of defeats the object of data encapsulation? Surely there must be a better way to tranfer the values from the Forms' controls back to the Class' properties?
Thanx aloud!
I have an ActiveX (DLL) project that contains a Public Class, a Form and a module. When the class is instantiated, one of the methods of the class is to show the Form, which acts basically as a visual interface to set the properties of the class. Now it's not that hard to access the properties of the class from the Form, but the only way I can see to set the properties in the class from the Form is to use public duplicate variables in a module, which is then accessable from the class. To me, this kind of defeats the object of data encapsulation? Surely there must be a better way to tranfer the values from the Forms' controls back to the Class' properties?
Thanx aloud!
Forget that just re-read the question.
I use the same approach as you are stating.
e.g.
Public Property Get MyProp() as String
MyProp = MyObject.MyProp
end Property
I use the same approach as you are stating.
e.g.
Public Property Get MyProp() as String
MyProp = MyObject.MyProp
end Property
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
bob online...
Clever! However, I can't seem to get it to work! I have done this...
<Class>
Private WithEvents frm as Form
Public Function ShowProperties()
Set frm = frmProperties 'this is the form with visual interface.
frm.Show vbModal 'this works fine!
End Function
>/Class>
<Form>
Public Event Test(Str as String)
Private Sub cmdOK_Click()
RaiseEvent Test("Test")
Unload Me
End Sub
</Form>
Now for some reason, the Class is not receiving the 'Test' event? I can't access the event proceedure from the drop-down list. I have even tried forcing an event...
Private Sub frm_Test(Str as String)
Msgbox str
End Sub
No joy, any ideas?
Clever! However, I can't seem to get it to work! I have done this...
<Class>
Private WithEvents frm as Form
Public Function ShowProperties()
Set frm = frmProperties 'this is the form with visual interface.
frm.Show vbModal 'this works fine!
End Function
>/Class>
<Form>
Public Event Test(Str as String)
Private Sub cmdOK_Click()
RaiseEvent Test("Test")
Unload Me
End Sub
</Form>
Now for some reason, the Class is not receiving the 'Test' event? I can't access the event proceedure from the drop-down list. I have even tried forcing an event...
Private Sub frm_Test(Str as String)
Msgbox str
End Sub
No joy, any ideas?
Try changing
RaiseEvent Test("Test")
Unload Me
for
RaiseEvent Test("Test")
DoEvents
Unload Me
Hope that is more help than the last comment.
RaiseEvent Test("Test")
Unload Me
for
RaiseEvent Test("Test")
DoEvents
Unload Me
Hope that is more help than the last comment.
Your declaration:
Private WithEvents frm as Form
Should be:
Private WithEvents frm as frmProperties
Now you should be able to select frm from left hand combo on code screen, and event Test from right hand combo
Private WithEvents frm as Form
Should be:
Private WithEvents frm as frmProperties
Now you should be able to select frm from left hand combo on code screen, and event Test from right hand combo
ASKER
Thank you to bob online and phildaley, with your combined answers it is now working perfectly. I want to split the award points between you - question is how.
Watch this space.... I'm off to find the answer.
Thankyou!
Watch this space.... I'm off to find the answer.
Thankyou!
ASKER
EE - please help with my previous comment.
Public Object as MyClass
and access it as follows
frm.Object.Property