Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 28th, 2005, 03:20 AM
Registered User
 
Join Date: Jul 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic object instantiation

I am trying to instantiate Form class dynamically. The class name is stored in the database.

for (int i=0;i<DSMenu.Tables[0].Rows.Count;i++)
{
if (<condition>)
{
Form objCurrFrm=new (Form) DSMenu.Tables[0].Rows[i][0].ToString();
}
}

This is giving me error “Type expected”

Any help will be appreciated

thanks
 
Old July 28th, 2005, 03:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am quite sure that you cannot do what you are trying for several reasons. You are trying to let a string be a type and furthermore you try to typecast it directly in the instantiation. Where have you seen this? Or is it something you have come up with yourself?

I don't know if it is possible in your case, but I use Activator.CreateInstance for a plug-in module I have done previously. You might want to check that one out.

Hope it helps and it is correct, Jacob ;)
 
Old July 28th, 2005, 11:20 PM
Authorized User
 
Join Date: Jul 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

YOu can use Reflection API using the System.Reflection namespace to do this task.

John Dirk
Programming Consulant
http://www.programminghelp4u.com - Programming (Assignment/Project) Help





Similar Threads
Thread Thread Starter Forum Replies Last Post
handling event for a dynamic object deepak_8282 General .NET 2 May 14th, 2007 12:42 PM
object instantiation madness GilkesM BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 9 March 10th, 2007 01:40 AM
dynamic variable/object names TheBFJ Excel VBA 2 November 13th, 2006 07:11 AM
XMLHttpRequest object instantiation AGS BOOK: Beginning Ajax with ASP.NET 4 September 25th, 2006 03:52 AM
dynamic class/object access tonyedmo C++ Programming 2 April 16th, 2005 03:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.