473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Reflection/Type Question

EdB
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?
Nov 21 '05 #1
5 1757
EdB,

Did you see this one already that I once made.

http://groups-beta.google.com/group/...bfdc42fec49419

I hope this helps,

Cor
Nov 21 '05 #2
"EdB" <Ed*@discussions.microsoft.com> schrieb:
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
Nov 21 '05 #3
EdB
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.

"Herfried K. Wagner [MVP]" wrote:
"EdB" <Ed*@discussions.microsoft.com> schrieb:
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
.
.
.
Public Sub Save() Implements ISaveable.Save
...
End Sub
End Class
..
..
..
Dim f As ISaveable = DirectCast(Me.ActiveMdiChild, ISaveable)
f.Save()
///

If you don't like this solution, take a look at 'CallByName':

Calling a method by its name
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=callbyname&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
"EdB" <Ed*@discussions.microsoft.com> schrieb:
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!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
EdB
Combined Doh! & Shazam!!!!!!

Perfect. Thanks much.

"Herfried K. Wagner [MVP]" wrote:
"EdB" <Ed*@discussions.microsoft.com> schrieb:
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!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
2
by: Dan | last post by:
Let's say I have a class like: class Dummy { public const string CONE = "one"; public const string CTWO = "two"; ... other stuff .... }
7
by: John | last post by:
I have a class the reads in a file and sets the values of the file into its properties. This class is used to populate the data onto a form. This form has controls created at runtime based on...
4
by: Bob | last post by:
If you rename a type at design time, the the task list shows what code broke, which happens to be a very nice list of dependant classes and methods. Is there any way to produce such dependency...
4
by: Andre Nogueira | last post by:
Hi guys I am developing a plugin-enabled application, and for that I am using reflection. I created an abstract ("MustInherit") class, from which all plugins must inherit. My question is......
1
by: Tony Johansson | last post by:
Hello! This is a question about Reflection. I have a small program below where the class are called Mymemberinfo. This class Mymemberinfo is used in GetMembers to get all the member for this...
5
by: heddy | last post by:
I understand that reflection allows me to discover the metadata of a class at runtime (properties, methods etc). What I don't understand is where this is useful. For example: If I am the sole...
4
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, what is the difference between the late binding and reflection? clara -- thank you so much for your help
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.