DirectCast

  • Thread starter Thread starter Merlin
  • Start date Start date
M

Merlin

Hi,

I want to call a procedure that exists in more than one form in my MDI
application - If I was to know the base form name I would use
"DirectCast(me.ActiveMdiChild, mybaseformname).callmyprocedure"

How do I call a procedure in my application that exists in more than one
created form, from the same code like above.

Thanks.

Merlin
 
Merlin,
Do all your forms inherit from mybaseformname?

Is callmyprocedure overridable in mybaseformname?

Have you overriden callmyprocedure in each of your derived forms?

If you have answered yes to all three of the above, then you can simple use:

DirectCast(me.ActiveMdiChild, mybaseformname).callmyprocedure


Alternatively if you have distinct routines in distinct forms, you can use
TypeOf with DirectCast.

If TypeOf me.ActiveMdiChild Is Form1
DirectCast(me.ActiveMdiChild, Form1).Method1
ElseIf TypeOf me.ActiveMdiChild Is Form2
DirectCast(me.ActiveMdiChild, Form2).Method2
ElseIf TypeOf me.ActiveMdiChild Is Form3
DirectCast(me.ActiveMdiChild, Form3).Method3
End If

I would favor the overridable method in the base form (method 1) over using
TypeOf, however they both are useful techniques.

A variation of the first method is to use an Interface instead of a base
form. An interface is useful if you want both Forms & Controls to have the
method to be called...

Hope this helps
Jay
 
* "Merlin said:
I want to call a procedure that exists in more than one form in my MDI
application - If I was to know the base form name I would use
"DirectCast(me.ActiveMdiChild, mybaseformname).callmyprocedure"

How do I call a procedure in my application that exists in more than one
created form, from the same code like above.

Define a common interface with a method and implement this interface in
the MDI child form classes. Then cast the 'ActiveMdiChild' to this
interface and call the method.
 
Back
Top