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

Way to get reference to object that called method?

Is there a way to get a reference to an object that called a method without passing the object to the method arguments? Thanks for reading.
Jul 29 '08 #1
6 1573
r035198x
13,262 8TB
Could you give more details of what you are trying to do? Static method or instance method?
This could be interpreted as

Expand|Select|Wrap|Line Numbers
  1. class {
  2.     void aMethod () {
  3.           //the this object called this method.
  4.     }
  5. }
for instance methods but perhaps that's not what you are looking for.
Jul 29 '08 #2
JosAH
11,448 Expert 8TB
Is there a way to get a reference to an object that called a method without passing the object to the method arguments? Thanks for reading.
You can't. The only thing you can do is create a Throwable, make it fill in its
stack trace and obtain the stack trace. Given the several elements you can obtain
the class name, method name and line number of the callers.

kind regards,

Jos
Jul 29 '08 #3
r035198x
13,262 8TB
You can't. The only thing you can do is create a Throwable, make it fill in its
stack trace and obtain the stack trace. Given the several elements you can obtain
the class name, method name and line number of the callers.

kind regards,

Jos
Cheating !
Jul 29 '08 #4
JosAH
11,448 Expert 8TB
Cheating !
Nah, I prefer to call it 'creative abuse' of the given core classes ;-)

kind regards,

Jos
Jul 29 '08 #5
Thanks for your replies guys! :) I was just wondering if it was possible, because it would be a easier way to solve my problem. I should have realized earlier though that something like that doesn't exist. I'm currently working on the other possible solution to the problem, and if i get stuck, I know where to ask if I need help again :).
Jul 30 '08 #6
BigDaddyLH
1,216 Expert 1GB
Thanks for your replies guys! :) I was just wondering if it was possible, because it would be a easier way to solve my problem. I should have realized earlier though that something like that doesn't exist. I'm currently working on the other possible solution to the problem, and if i get stuck, I know where to ask if I need help again :).
You never explained your problem. If you did, a forum member may be able to suggest something better -- at least something that isn't a hack!
Jul 30 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Murat Tasan | last post by:
i have a quick question... is there a way to obtain the reference to the object which called the currently executing method? here is the scenario, i have a class and a field which i would like to...
14
by: Michael Winter | last post by:
In an attempt to answer another question in this group, I've had to resort to calling the DOM method, Node.removeChild(), using a reference to it (long story...). That is, passing Node.removeChild....
7
by: Nick Zdunic | last post by:
I have a remotable object running in my host application. The host starts up and creates the object. Within a method to start the remote object doing its thing it creates an object. ...
5
by: Jerry Morton | last post by:
Hi, I'm new to C# and have run into a problem of my own making! I originally took from the documentation that as long as I didn't use the "ref" keyword in method declarations, that everything...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
7
by: Marcelo | last post by:
Hi everybody, I don't understand why I am having a problem in this code. The problem is that my pointer *phist in main method, it is declared. Then I send the pointer to my method, and this...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
5
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The thing that troubles me about pass-by-reference into...
4
by: johnxhc | last post by:
We have a project in .NET 1.1 , some of the .NET methods take COM interface reference pointer as a parameter, somehow we have to call Marshal.ReleaseComObject to release the COM Object, otherwise...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.