* Armando:
I would like to know how (if its possible) to declare two (or more)
string variables into one and use this string to point to an (existing)
Object.
I tried the following but it goves me an error at run-time.
On the form I placed a Label (called Label1) and a Button. The
following code is in the On Click event of the button.
String lsFirst = "Label";
String lsLast = "1";
String lsString = lsFirst + lsLast;
TLabel * lbl = (TLabel *) &lsString;
lbl->Caption = "Hello"; //Gives an error at run-time!
Thanks for any help.
The above code is based on a misconception of what kind of language C++ is.
Some languages, such as command interpreter languages, are based on run
time interpretation of the program text, which can be executed directly;
this is achieved by having the program text executed by a /program/.
Some languages, such as Lisp and JavaScript and even to some degree Java
and C#, are in-between in that they allow program text to be translated
to something executable at run time; this is achieved by some pretty
ingenious mechanisms that allow executable code to be added at run-time,
and then it's just a matter of plugging in the code produced by some
translation function.
Some languages, such as C++, are based on all translation of the program
text to executable form having been done prior to execution of the
program: no further translation at run time is supported (in standard
C++). In other words, standard C++ does not have a mechanism for adding
executable code at run time, and does not openly support that. However,
a very primitive and course-grained such mechanism, dynamic libraries,
is tacitly supported by suitably vague language in the standard, so that
actual C++ compilers for Windows and *nix do support dynamic libraries,
but in platform-specific and compiler-specific ways (off-topic here).
Having everything translated prior to execution allows for better
efficiency and more strict and global static type checking, but as you
have now experienced, it limits what you can do "directly".
Chances are that the Label and Button and other GUI classes you're using
do support look-up by name, and by using that functionality you can
achieve what you're trying to do without translating text to executable
code at run time.
However, that's off-topic in this group (it's not a C++ issue), and
furthermore, chances are that you're trying to do something really
simple in a really convoluted and complex way, i.e., that a solution to
the problem indicated above would be Very Bad Solution to the Real
Problem (which you should post in Borland or Windows programming group).