swapna
08-02-2005, 06:10 AM
Hi all,
I have a form in a dll which will be loaded dynamically using "createobject" in my main application.
Now I need to handle the events raised by the form in the dll from my main application.
Can anyone give me any suggestion regarding this?
Thanks,
Swapna.
the master
08-02-2005, 06:46 AM
you could just add all the events in manually then in each event on your form tell it to run one from the dll
+- in the dll code -+
public sub form_load()
end sub
+- in the form code -+
private sub form_load()
mydllvariable.form_load
end sub
swapna
08-02-2005, 06:56 AM
you could just add all the events in manually then in each event on your form tell it to run one from the dll
+- in the dll code -+
public sub form_load()
end sub
+- in the form code -+
private sub form_load()
mydllvariable.form_load
end sub
I have loaded the form from the other dll. I just want to handle the events (manual events like OnProgress, OnCompletion,...) raised by the form in the dll.
TeraBlight
08-02-2005, 04:45 PM
This isn't my area of expertise, but I'll give it a try since nobody else has answered so far.
If you can use early binding, you just declare the object variable holding the form wrapper "WithEvents" and use the events as you normally would:
Private WithEvents f As myDllForm
Private Sub f_MouseHover(X As Single, Y As Single)
'...
End Sub
If you need it to be late-binding, you cannot use proper events but have to use a callback method instead, since variables typed as "Object" cannot be WithEvents:
in a dll-class wrapping the dll-form:
Private WithEvents f As dllForm
Private s As Object
Private Sub Class_Initialize()
Set f = New dllForm
End Sub
Private Sub f_MouseHover(X As Single, Y As Single)
Call s.MouseHover(X, Y)
End Sub
Public Property Set eventSink(newSink As Object)
Set s = newSink
End Property
in e.g. a form in the main app:
Private mDllForm As Object
Private Sub Form_Load()
Set mDllForm = CreateObject("dllName.dllClass")
Set mDllForm.eventSink = Me
End Sub
Public Sub MouseHover(X As Single, Y As Single)
'...
End Sub
Ideally, this would be done using interfaces of some sort to ensure that the eventSink provides the required functionality, but I wouldn't know where to define them...
I hope someone will correct me quickly if there is a better way of doing this :)