Click to See Complete Forum and Search --> : Communicating between forms


vzcharlie
March 13th, 2001, 10:03 AM
Is there a way to call user-defined functions in other forms via a pointer? I need to close windows that are docked to my main form using a function that creates a sliding effect. I want to point to that function on a mouse click event on the form for all possible open windows with the same function.

Clearcode
March 13th, 2001, 10:08 AM
If the form's subs are public, you can refer to them directly thus:

' In frmCustomer
public Sub RefreshCustomerDetails()
'..yadda yadda yadda
End Sub
'in frmMain
Call frmCustomer.RefreshCustomerDetails()




HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com

vzcharlie
March 13th, 2001, 10:37 AM
I don't want to hard code the form names into the main form because I want to be able to add extra forms without having to update the main form. Any suggestions?

Clearcode
March 13th, 2001, 10:51 AM
Aha - in that case you need "Implements"

Create a class file called something like: IDockableForm with all the things a dockable form does, but no code filled in.

'\\ IDockableForm
'\\ Interface Inhertance class
public Enum enDockTargets
enDTLeft = 1
enDTRight = 2
enDTTop = 3
enDTBottom = 4
End Enum

public Sub DockToBorder(byval Target as enDockTargets)
'no code here....
End Sub




Now in each for, in the declarations part:

Implements IDockableForm

'This will create:
public Sub IDockableForm_Dock(byval Target as enDockTargets)
'put actual implementation of the docking behaviour here
End Sub




And then in your main code, iterate the Forms collection and if they implement IDockableForm, call the IDockableForm_Dock method.

Dim frmThis as IDockableForm

for Each frmThis in Forms
If Not frmThis is nothing then
Call frmThis.Dock(enDTLeft )
End If
next frmThis




Read the help on the implements keyword for more info....

HTH,
Duncan


-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com