473,812 Members | 2,984 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the name of an object - is it possible?

Hi All,

Just wondering if it is possible to get the name and class name of an
object?

oC = new control("name", "something" );
..

oAnRef = oC;.
..
now both oC and oAnRef pointing to the same object of class "control"

is it possible to get the name of the class? in this case it is a string:
"control"

is it possible to get the name ( or string representation ) of the var:

function MyName(){
????????
}

cName = oC.MyName();

so MyName would hold string "oC"

TIA,

Tom


Jul 23 '05 #1
3 1042
On Fri, 26 Nov 2004 16:05:45 +1000, Tom Szabo <to*@intersoft. net.au> wrote:
Just wondering if it is possible to get the name and class name of an
object?


No.

You can get a reference to the constructor function of an object with

objRef.construc tor

but that won't give you the name of the function.

You certainly can't get the identifier name an object is assigned to. As
you pointed out yourself, an object can be referred to by more than one
identifier.

What are you attempting to accomplish? You might be looking in the wrong
direction.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
> is it possible to get the name of the class? in this case it is a string:
"control"
I think you use the "constructo r" property.

I.e.

var myClass=oC.cons tructor;

is it possible to get the name ( or string representation ) of the var:

function MyName(){
????????
}

cName = oC.MyName();

so MyName would hold string "oC"


I don't think that objects keep track of what variables reference
them. An object could be referenced by one or more variables, so it
would be quite an overhead for that object to have to track all of
those variables.

This can lead to memory leaks if you have circular references:
o1-->o2-->o1.
Jul 23 '05 #3
Thanks :-(((

"Julian Turner" <ju****@baconbu tty.com> wrote in message
news:c4******** *************** ***@posting.goo gle.com...
is it possible to get the name of the class? in this case it is a string: "control"


I think you use the "constructo r" property.

I.e.

var myClass=oC.cons tructor;

is it possible to get the name ( or string representation ) of the var:

function MyName(){
????????
}

cName = oC.MyName();

so MyName would hold string "oC"


I don't think that objects keep track of what variables reference
them. An object could be referenced by one or more variables, so it
would be quite an overhead for that object to have to track all of
those variables.

This can lead to memory leaks if you have circular references:
o1-->o2-->o1.

Jul 23 '05 #4

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

Similar topics

2
6931
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This inteface has a lot more methods which works fine, it is just the
6
22541
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was 'myDog' without having to pass it as a parameter. //////////////////////////////// function...
8
8521
by: bryan | last post by:
Is there any way I can get the application path (the one returned by Request.ApplicationPath) in the Application_Start method in Global.asax? Request is not valid there. On a related note, is there a way to get it from a static method in an aspx page, or in the class (static) constructor for an aspx page? Thanks, Bryan
4
8508
by: Joe Schmoe | last post by:
All I want to to be able to take a two-column DataReader (One column with the Item ID number, the other with Item Description text) and load it into a Windows Forms ComboBox (Set to DropDownList mode) so that I the dropdown shows the Item Descriptions, but returns the Item ID number when selected. Completely easy in ASP.NET, but I cannot figure out how to do the same in a Windows Forms app. Obviously the Windows Forms ComboBox is a lot more...
3
3879
by: Atul | last post by:
Hi, I am running .NET Framework 2.0 on windows XP SP2. I am stuck in a situation where I need to find out a list of all active sessions running in IIS for a web application. I know that .NET 2.0 has introduced a new class that facilitate this task very easily, somehow couldnt recall its name. Any help would be highly appreciated.
5
2314
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or System.CodeDom.CodeCastExpression) __problem typecast #1 Desc:i do needed checks but data/commands in XML is dynamic and i don't wanna fix C# code again and again... Sample:foreach (object some in somearray) (some.GetType())some.someaction();
6
6250
by: bill | last post by:
Thanks to those that taught me to use heredoc to embed html in php. I don't want to start the html in php vs php in html discussion again., heredoc works a treat for that which I am doing except: In the generated html I have a number of checkboxes. I fill in the checkboxes from a boolean value in a mySQL table. To make this easier I use a function that takes the boolean and return either 'checked' or ''. This worked well when I was...
6
2039
by: Adam Atlas | last post by:
Is it possible for an object, in its __init__ method, to find out if it is being assigned to a variable, and if so, what that variable's name is? I can think of some potentially ugly ways of finding out using sys._getframe, but if possible I'd prefer something less exotic. (Basically I have a class whose instances, upon being created, need a 'name' property, and if it's being assigned to a variable immediately, that variable's name would...
185
7150
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will return the file name given a FILE *. Questions: What would be the best name for this function?
0
9734
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9219
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7677
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.