Reflection/Type Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an MDI form with similar child edit forms. The child Edit forms have
public methods that of consistent names. I have a tool bar that calls these
methods. Here's how I'm doing it now (toolbar click event).

1) Dim f As Object
2) Select Case Trim$(ActiveMdiChild.Text)
3) f = CType(ActiveMdiChild, <Hard Coded Valid Form Object Based On Case>)
4) f.<Public Method>

Now, I know that I could use an inherited form, but for a number of reasons,
I am trying to stay awau from that. I was hoping to extract the type from
ACTIVEMDICHILD and use that in my CType statement to eliminate the Select
Cases, but I can not find a Syntax that works.

I've tried things like

f = CType(ActiveMdiChild, ActiveMdiChild.GetType)

etc....

Any help?
 
EdB said:
I have an MDI form with similar child edit forms. The child Edit forms
have
public methods that of consistent names. I have a tool bar that calls
these
methods. Here's how I'm doing it now (toolbar click event).

1) Dim f As Object
2) Select Case Trim$(ActiveMdiChild.Text)
3) f = CType(ActiveMdiChild, <Hard Coded Valid Form Object Based On Case>)
4) f.<Public Method>

Now, I know that I could use an inherited form, but for a number of
reasons,
I am trying to stay awau from that. I was hoping to extract the type from
ACTIVEMDICHILD and use that in my CType statement to eliminate the Select
Cases, but I can not find a Syntax that works.

Instead of inheriting from a common base class that provides the method,
consider writing an interface which is implemented by the child form
classes:

\\\
Public Interface ISaveable
Sub Save
End Interface
..
..
..
Public Class ChildForm1
Inherits Form
Implements ISaveable
 
OK, I like this solution, however.....I am having an issue executing it.

1. I defined this:

Public Interface PrintChildForm
Sub PrintMe()
End Interface

2. I modified my form like this:

Public Class ProfileEdit
Inherits System.Windows.Forms.Form
Implements PrintChildForm

3. And I changed my sub as follows:

Public Sub PrintMe() Implements PrintChildForm.PrintMe

However....when I try to call it in the MDI like this:

Dim x As PrintChildForm = DirectCast(Me.ActivateMdiChild,
PrintChildForm)

I get a compile error on "Me.ActivateMdiChild" that says

Argument not specified for parameter 'form' of 'Protected Sub
ActivateMdiChild(form As System.Windows.Forms.Form)'.

I have no idea what parameter it's looking for.
 
EdB said:
Public Interface PrintChildForm
Sub PrintMe()
End Interface

The name of an interface "should" start with "I" to make it more obvious
that it's an interface.
Dim x As PrintChildForm = DirectCast(Me.ActivateMdiChild,
PrintChildForm)

I get a compile error on "Me.ActivateMdiChild" that says

'ActivateMdiChild' is a method. Use the 'ActiveMdiChild' property instead!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top