Results 1 to 4 of 4

Thread: how can i pass "this" as parameter?

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    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);

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.
    }
    }

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    it doesnt work...the class witch is callin is a bTab class..and it doesnt work neither as bTab sender or object sender...

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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
  •  



Click Here to Expand Forum to Full Width