🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages Started by Brian Dumas Thu, 10 Apr 2003 20:48
odd question...how to know variable name
#17033
Author: Brian Dumas
Date: Thu, 10 Apr 2003 20:48
12 lines
1411 bytes
Is this possible (I think not, but heck, I'll ask anyway)

lets say I have a class TMyClass.

When a user has a variable of TMyClass, can my class know the variables
name. For example
TMyClass AAA;

Is there a way for my constructor, or any class function to "know" that the
instance name is "AAA"? I want o use it for named shared memory.

thanks, Brian
Re: odd question...how to know variable name
#17034
Author: Ed Mulroy [TeamB]
Date: Thu, 10 Apr 2003 21:08
20 lines
1647 bytes
At compile time the name of a variable, including the name of an instance of
a class, is known.  When the function of compiling and linking is done the
name is no longer known.

.  Ed

> Brian Dumas wrote in message
> news:3e95d8a6$1@newsgroups.borland.com...
>
> Is this possible (I think not, but heck, I'll ask anyway)
>
> lets say I have a class TMyClass.
>
> When a user has a variable of TMyClass, can my class
> know the variables name. For example
> TMyClass AAA;
>
> Is there a way for my constructor, or any class function
> to "know" that the instance name is "AAA"? I want o
> use it for named shared memory.
Re: odd question...how to know variable name
#17036
Author: Remy Lebeau (TeamB)
Date: Fri, 11 Apr 2003 01:17
17 lines
1446 bytes
"Brian Dumas" <brian@kvdco.com> wrote in message
news:3e95d8a6$1@newsgroups.borland.com...

> Is there a way for my constructor, or any class function
> to "know" that the instance name is "AAA"?

Nope.  Variable names don't exist at runtime, they are resolved to memory
addresses at compile time.

> I want o use it for named shared memory.

Just pass a string literal as another parameter to the constructor and use
that instead.


Gambit
Re: odd question...how to know variable name
#16979
Author: Ron Sommer
Date: Sat, 12 Apr 2003 10:05
17 lines
1952 bytes
> Is there a way for my constructor, or any class function to "know" that the
> instance name is "AAA"? I want o use it for named shared memory.


Variables have a very small scope compared to shared memory segments. 
Therefore, it wouldn't be a good idea to name shared memory segments 
after variable names: Better try to use unique names, created from a 
unique property of the variable to use, e.g. memory location, or a 
global counter.

However, you can enhance classes so that they register automatically 
with a list or container at creation. You'd of course have to hand over 
the name of the variable in an extra string, so that it can be stored in 
this list. In general, I really don't recommend that, but, of course, I 
don't know what you need that for.

Ron Sommer
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads