473,396 Members | 2,013 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,396 software developers and data experts.

Refering to an object by composing variables in C++ BUILDER

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.

Armando V.

Jul 15 '06 #1
4 1638
Armando wrote:
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.
How can we tell without knowing what a String or a TLabel is?

--
Ian Collins.
Jul 15 '06 #2
* 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).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 15 '06 #3
"Armando" <vi******@gmail.comwrote in message news:11**********************@75g2000cwc.googlegro ups.com...
I would like to know how (if its possible) to declare two (or more)
string variables into one
How do you declare one object "into" another? That string of
words conveys nothing to me.
and use this string to point to an (existing)
Object.
If by "string" you mean "std::string", then no, strings are not
pointers; they don't "point to" anything. They are objects.
You can change their value, yes. You can assign one to another,
yes. For example:

std::string s1 ("Good Golly ");
std::string s2 ("Miss Molly ");
std::string s3 ("Fred");

s3 = s1 + s2; // s3 is now "Good Golly Miss Molly"
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!
What is "String" with a capital "S"?

What is "TLabel"?

Why are you typecasting the address of a "String" to a "TLabel"
pointer? In my humble opinion, that is ill-advised no matter what
"TLabel" and "String" are. Typecasts are a good way to make code
that shuts-up the compiler's errors and warnings by telling it
sweet-sounding lies at compile time, at the cost of crashing a lot
at run time. Don't use typecasts. They're the work of Morgoth.
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/
Jul 15 '06 #4
In article <11**********************@75g2000cwc.googlegroups. com>,
vi******@gmail.com says...
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.
Not directly -- but you might want to look up std::map.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 16 '06 #5

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

Similar topics

3
by: Lorenzo Polidori | last post by:
Hi all, I have to display an MPEG2 stream in my C++ application. I have seen the Media Player Object of Borland C++Builder 6 can have as input a file specified in Filename property of this media...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
44
by: Steven T. Hatton | last post by:
This may seem like such a simple question, I should be embarrassed to ask it. The FAQ says an object is "A region of storage with associated semantics." OK, what exactly is meant by "associated...
17
by: Zeng | last post by:
I'm trying to comparing 2 objects (pointer to object) to see if they are the "same" as each other. Here is what the definition of being the "same" object type for both objects, object 1, ...
6
by: flaavia | last post by:
Hello My oleDbDataAdapter1 seems to be limited to 99 variables in SQL-statements. At least it does give an error when tying to address more than 99 Does anyboda know if that is a fixed limit...
2
by: Norton | last post by:
Dear all, I have created many objects Currently i create a toString function, which is to list all variables value inside this object Somthing like Public Class ABC Dim sName as string =...
3
by: rsine | last post by:
I have searched around a little and have yet to find a naming convention for the string builder object. I really do not want to use "str" since this is for string objects and thus could be...
13
by: bob the builder | last post by:
Can i get the class of an object of which i only have the address? Lets say i have 3 classes: AClass,BClass,CClass. i also have an object of each class: aObject, bObject, cObject And finally i...
45
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.