|
-
Nov 15th, 2002, 07:23 PM
#1
Thread Starter
yay gay
how can i pass "this" as parameter?
i want to pass a class as parameter so it can be later used...i tryed making
function(object myClass)
but that didnt work..how do i do ? i want that in the end i make function(this);
-
Nov 15th, 2002, 09:23 PM
#2
PowerPoster
You can pass in 'this' if the object argument for the function accepts that type of object. Example (may not be 100 percent right, didn't get to test them):
You have a Form1 class and you are calling a function from it:
MyClass.Function(this)
class MyClass
{
public void Function(Form1 obj)
{
// Use your object.
}
}
OR
class MyClass
{
public void Function(System.Windows.Forms.Form obj)
{
// Cast obj into a Form1 variable
Form1 f = (Form1)obj;
// f now holds the pointer to the object you passed in.
}
}
-
Nov 16th, 2002, 06:32 AM
#3
Thread Starter
yay gay
it doesnt work...the class witch is callin is a bTab class..and it doesnt work neither as bTab sender or object sender...
-
Nov 16th, 2002, 11:51 AM
#4
PowerPoster
You can pass it as an object but you will have to cast it to the appropriate type before accessing any of its members.
Code:
((MyClass)o).Name // access member like this..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|