|
-
Jun 6th, 2002, 06:46 AM
#1
Thread Starter
Addicted Member
Interface dll in ocx
Hi
I have an interface that I have put in a separate dll.
I implement this interface in a user control ocx.
In my main program, i have the dll and ocx referenced,
and I load the user control depending on which form is showing.
I use this code to do it:
VB Code:
Private Sub Form_Load()
Dim oCtl As Object
Dim ctlMain As FormControls.ctlBuy
Dim clsMain As FormClasses.clsForm
Set oCtl = Controls.Add("FormControls.ctlBuy","ctlCur")
Set ctlMain = oCtl
' I set the control's properties and show it here...
Set clsMain = ctlMain
End Sub
This works fine until the statement 'Set clsMain = ctlMain'.
This gives a type mismatch error.
The dll is compiled with binary compability, and was compiled
before I started making my user control. I have checked that
it is the same dll that is referenced both from the main app and
from the ocx project.
What am I doing wrong here?
-
Jun 8th, 2002, 06:55 AM
#2
Hyperactive Member
ctlMain and clsMain must implement the same interface. Do they?
-
Jun 10th, 2002, 03:34 AM
#3
Thread Starter
Addicted Member
Interface
The FormClasses.dll contains just one class module,
which is clsForm. clsForm is implemented in FormControls.ctlBuy.
I then try to define an object of type clsForm, and set this to
be an instance of FormControls.ctlBuy.
It worked fine as long as i had all the class modules, user
controls, and forms in the same project, but when i split the
project into 3 parts, 1 ocx, 1 dll, 1 exe, i got the type mismatch
error message.
So clsMain is the interface class, and ctlMain implements that class.
-
Jun 10th, 2002, 05:26 AM
#4
Hyperactive Member
Have you tried taking out the intermediary - you don't need both oCtl and ctlMain.
Code:
Set ctlMain = Controls.Add("FormControls.ctlBuy","ctlCur")
' I set the control's properties and show it here...
Set clsMain = ctlMain
If this still gives a type mismatch error, then there's something wrong with your interfaces or controls.
Just a tip - give things more obvious names. The coding convention for interface classes is to prefix with "I" - FormClass.IForm for example. Classes which implement this interface are prefixed with "C" to stand for Concrete. Objects are prefixed with obj or nothing at all... so (Just IMHO of course):
Code:
Dim objCtl As Object
Dim objBuy As FormControls.CBuy
Dim objForm As FormClasses.IForm
-
Jun 10th, 2002, 07:16 AM
#5
Thread Starter
Addicted Member
Test project
OK.. I did a simple test project, and got the same problem.
Here is what I have:
FormClasses.IForm:
VB Code:
Option Explicit
Public Property Let ControlCaption(ByVal sCaption As String)
End Property
Public Property Get ControlCaption() As String
End Property
FormControls.ctlLabel:
VB Code:
Option Explicit
Implements FormClasses.IForm
Private Property Get IForm_ControlCaption() As String
IForm_ControlCaption = Label1.Caption
End Property
Private Property Let IForm_ControlCaption(ByVal RHS As String)
Label1.Caption = RHS
End Property
prjTest:
VB Code:
Option Explicit
Private Sub cmdTest_Click()
Dim ctl As FormControls.ctlLabel
Dim cls As FormClasses.IForm
Set ctl = Me.Controls.Add("FormControls.ctlLabel", "lblNew")
ctl.Top = cmdTest.Top + cmdTest.Height
ctl.Left = cmdTest.Left
ctl.Visible = True
Set cls = ctl
cls.ControlCaption = "Hello"
Set cls = Nothing
Set ctl = Nothing
End Sub
I still get the Type Mismatch error in the line "Set cls = ctl"
I noticed that VB changes the sCaption parameter to RHS,
but changing it back to sCaption in the usercontrol doesn't
make any difference.
-
Jun 10th, 2002, 11:45 AM
#6
Hyperactive Member
In that case I can't see anything wrong. It all looks fine... perhaps it's something to do with the Controls.Add method... try using a control array instead, and using the Load statement to create a new instance.
-
Jun 11th, 2002, 03:15 AM
#7
Thread Starter
Addicted Member
Solved (?)
I just changed the line
to
This seemed to do the trick,
although I have no idea why it should.
Thanks for your help ChiefRB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|