create instance of a class from a string 
Author Message
 create instance of a class from a string

Hi all

I was wondering if it is possible to create an instance of a class when
having the call to the constructor in a string like this :

dim constructor_string as string
dim customerid as integer

customerid = 234

constructor_string = "new customer(customerid)"

mycustomer = customer_creator(constructor_string)

private function customer_creator(strConstr as string) as customer

' ''''' Here goes my missing code (constructs the customer with id 234)
'''''''

return 'createdCustomer'

end function

is this possible in any way ??

Thanks in advance

Allan



Sun, 30 Jan 2005 20:11:33 GMT  
 create instance of a class from a string
Look into the Activator class, it will do all of this for you.

Cheers

--
Robert Chapman
Manager, Applications Development
prairieFyre Software Inc.
http://www.prairiefyre.com

Quote:
> Hi all

> I was wondering if it is possible to create an instance of a class when
> having the call to the constructor in a string like this :

> dim constructor_string as string
> dim customerid as integer

> customerid = 234

> constructor_string = "new customer(customerid)"

> mycustomer = customer_creator(constructor_string)

> private function customer_creator(strConstr as string) as customer

> ' ''''' Here goes my missing code (constructs the customer with id 234)
> '''''''

> return 'createdCustomer'

> end function

> is this possible in any way ??

> Thanks in advance

> Allan



Sun, 30 Jan 2005 20:46:25 GMT  
 create instance of a class from a string

Quote:
> Look into the Activator class, it will do all of this for you.

> Cheers

> --

I am doing just that, but I just can't get the hang of it  :o(

I believe I have to use this :

Overloads Public Shared Function CreateInstance( _
   ByVal type As Type, _
   ByVal args() As Object, _
   ByVal activationAttributes() As Object _
) As Object

but I don't know how to use the args and activationAttributes

I can't find any examples, if you have any experience with this I would very
much appriciate an example.

Thanks in advance

Allan



Sun, 30 Jan 2005 21:21:42 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Return class instance as a string

2. Create an instance from the class name?

3. Using reflection to create class instance

4. Creating a new instance of Winsock in a Class Module

5. ASP - create in just script instance of class provided in current page with different language

6. Using New to create instances of a class in MTS componant

7. Want to create only ONE instance of class

8. Using New to create instances of a class in MTS componant

9. Create Instance of class in running activeX.exe??

10. Create an instance of a Timer obeject in a class

11. dynamically creating instances of classes

12. Creating DateTime instances from a string

 

 
Powered by phpBB® Forum Software