Andy214 Level: Trainee
 Registered: 26-12-2003 Posts: 3
|
Re: passing objects in ocx control
For ActiveX project, to pass controls like Forms, TextBox, etc... you can only use late binding, e.g. declare as Object
Public Sub DoSomething(frm As Object)
...
End Sub
To further make sure the object is the one you expect, you can do type checking in your code (e.g.)
If TypeOf frm Is Form Then
End If
NOTE:
There's a problem tough I notice, is when I have 2 development PC, say A and B, and I have compile the OCX on both PC before.
When I compile in PC A, then I bring the project (with OCX) to PC B to continue development, no error BUT the OCX didn't work as expected (I'm using Binary Compatibility, and in the OCX I passed in a control which then I checked if the TypeOf matches the control I will set reference to).
What I mean by didn't work as expected is, it didn't SET the variable in my OCX to the object passed in in PC B, but its working fine in PC A.
When I re-compile in PC B, it works fine already, but when I bring back to PC A, it's not working as expected AGAIN, I have to recompile...
So, I decided to use Debug.Print to let me know what is actually happening.
I notice this, let say I pass in a TextBox object, during checking of TypeOf (e.g. TypeOf ctrlpassedin Is TextBox)
1. In the SAME development PC I compile, it returns TRUE.
2. In the other development PC, it returns FALSE. (When it's actually a TEXTBOX! )
Any ideas ?? I think it has something to do with the registry settings (when you compile)... or its just another VB Bug?
____________________________
-Andy214-
|