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

Create objetc dynamically

Hi,

I need help for the following problem :
At the start of my application, i found the items of the configuration in
the register. This items represent tools connected to the system at this
moment.
I have a class named "Machine_Tools" for drive the tools by an RS232 series
communication.
These items are stored like string so i have a string table to catch them.
exemple : items are like "AX001", "AX002", etc ... and they have spécifics
caractéristics for acces to.(stored in subskeys).

So I need to create objects whose the name is "AX001" or "AX006", or .... to
be able to drive them
How can i do to make something like :
"Machine_Tools <Variable> = new Machine_Tools(); " where <Variable> content
the name of the Machine_Tool object , so that i could make "AX001.start()"
or other public method of this object in my program ?
How can i do to execute the inside of a variable ?

Thank a lot for your help ...

Bruno
Nov 17 '05 #1
2 1044
Variable names are only useful for the compiler. When the code compilers,
the symbols are transmitted to generic references and therefore any variable
that might be named AX001 would not make any sense at runtime. What you
might need is maybe a Hashtable where you can associate a key, in this case
a text string, with an object. For instance,

Hashtable hash = new Hashtable();
hash.Add("AX001", new Machine_Tool());
hash.Add("AX002", new Machine_Tool());

((Machine_Tool)hash["AX001"]).start();
"Bruno Remeyse" <br***********@wanadoo.fr> wrote in message
news:u1**************@TK2MSFTNGP14.phx.gbl...
Hi,

I need help for the following problem :
At the start of my application, i found the items of the configuration in
the register. This items represent tools connected to the system at this
moment.
I have a class named "Machine_Tools" for drive the tools by an RS232 series communication.
These items are stored like string so i have a string table to catch them.
exemple : items are like "AX001", "AX002", etc ... and they have spécifics
caractéristics for acces to.(stored in subskeys).

So I need to create objects whose the name is "AX001" or "AX006", or .... to be able to drive them
How can i do to make something like :
"Machine_Tools <Variable> = new Machine_Tools(); " where <Variable> content the name of the Machine_Tool object , so that i could make "AX001.start()"
or other public method of this object in my program ?
How can i do to execute the inside of a variable ?

Thank a lot for your help ...

Bruno

Nov 17 '05 #2
It's a very good solution.
Thank a lot for your help.

Bruno
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:e4**************@tk2msftngp13.phx.gbl...
Variable names are only useful for the compiler. When the code compilers,
the symbols are transmitted to generic references and therefore any
variable
that might be named AX001 would not make any sense at runtime. What you
might need is maybe a Hashtable where you can associate a key, in this
case
a text string, with an object. For instance,

Hashtable hash = new Hashtable();
hash.Add("AX001", new Machine_Tool());
hash.Add("AX002", new Machine_Tool());

((Machine_Tool)hash["AX001"]).start();
"Bruno Remeyse" <br***********@wanadoo.fr> wrote in message
news:u1**************@TK2MSFTNGP14.phx.gbl...
Hi,

I need help for the following problem :
At the start of my application, i found the items of the configuration in
the register. This items represent tools connected to the system at this
moment.
I have a class named "Machine_Tools" for drive the tools by an RS232

series
communication.
These items are stored like string so i have a string table to catch
them.
exemple : items are like "AX001", "AX002", etc ... and they have
spécifics
caractéristics for acces to.(stored in subskeys).

So I need to create objects whose the name is "AX001" or "AX006", or ....

to
be able to drive them
How can i do to make something like :
"Machine_Tools <Variable> = new Machine_Tools(); " where <Variable>

content
the name of the Machine_Tool object , so that i could make
"AX001.start()"
or other public method of this object in my program ?
How can i do to execute the inside of a variable ?

Thank a lot for your help ...

Bruno


Nov 17 '05 #3

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

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
5
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
7
by: pmclinn | last post by:
I was wondering if it is possible to dynamically create a structure. Something like this: public sub main sql = "Select Col1, Col2 from Table a" dim al as new arraylist al =...
8
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.