473,320 Members | 1,883 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,320 software developers and data experts.

generic Form frmX = new based on class name

I have an application where I say essentially:

Type typeForm = Type.GetType(stringPassedIn)
Form frmX = null;
if (typeForm == Type.GetType("somenamespace.someform") {
frmX = new somenamespace.someform()
} else if (typeForm = Type.GetType("somenamespace.anotherform") {
frmX = new somenamespace.anotherform()
} else ....// and so an ad naseum for all the forms

Every time we add a form, we have to add it to this code. I want something much more generic.

What I want to be able to do is something like this

Type typeForm = Type.GetType(stringPassedIn)
Form frmX = new //something that uses the typeForm or stringPassedIN

Regards,

Madman Pierre aka Peter Horwood

Nov 16 '05 #1
1 1243
madmanpierre <ma**********@discussions.microsoft.com> wrote:
I have an application where I say essentially:

Type typeForm = Type.GetType(stringPassedIn)
Form frmX = null;
if (typeForm == Type.GetType("somenamespace.someform") {
frmX = new somenamespace.someform()
} else if (typeForm = Type.GetType("somenamespace.anotherform") {
frmX = new somenamespace.anotherform()
} else ....// and so an ad naseum for all the forms

Every time we add a form, we have to add it to this code. I want
something much more generic.
If you're going to have to do specific things for different types, you
might as well avoid using GetType so often and do straight string
comparisons:

Form frmX = null;
switch (stringPassedIn)
{
case "somenamespace.someform":
frmX = new somenamespace.someform();
break;

// etc
}
What I want to be able to do is something like this

Type typeForm = Type.GetType(stringPassedIn)
Form frmX = new //something that uses the typeForm or stringPassedIN


Use Activator.CreateInstance.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

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

Similar topics

49
by: Steven Bethard | last post by:
I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
2
by: Matt | last post by:
Can form.submit() submit another form? In the following example, in page1.asp, it is fine to submit the current form: form1.submit(), and and I could see the value "Joe" in page2.asp. However, if I...
3
by: VMI | last post by:
In my Windows application, the main Form (Form_Main) calls a small Form (Form_X) that checks a file. Basically, I pass the name of the file through frmX's constructor and then I display it with...
5
by: Richard Brown | last post by:
Ok, I've been looking through the .NET SDK docs and stuff. I'm wondering if you can provide a control extender that does generic validation or functionality just by dropping it on the form. For...
2
by: Steve | last post by:
I have a .NET windows program that has a VB.NET component and a C# component. The VB component contains the form and handles all the UI stuff. The C# component drives the engine that actually does...
4
by: DNK | last post by:
Hi, how to unload a form in vb.net (equivalanet code for vb6 - ) thanks dnk.
6
by: reidarT | last post by:
In vb6 I use form.show to open a form. How do I open forms in vb.net? regards reidarT
3
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.