CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: ME.?

  1. #1
    Join Date
    Sep 1999
    Location
    Colombo, Sri Lanka
    Posts
    27

    ME.?


    In an arbitary function. Could I pass a reference to it to another function?



    function f1 (nVal as Integer)

    nNewVal = nVal + 1

    f2(me)

    end function




    function f2(hFunction as Object)as Integer

    f2 = hFunction.nNewVal + 1

    end function





    Is this sort of thing possible... I know with the ME keyword you may have access to all the objects etc.. but how do you get access to parameters that were passed to that function etc?

    Thanks

    Rob.


  2. #2
    Join Date
    Oct 1999
    Location
    CA
    Posts
    91

    Re: ME.?

    Functions aren't objects, so I don't think you could ever use the Me.
    Hmmmm.... But what if you declared the function as an object? I suppose that only means that it's returning an object, but it its self isn't one.
    I think this would be possible then...


    Function f1 () as Object

    ...

    f2(f1)

    ...

    End Function

    Function f2 (objFunct as Object) as Variant

    ...




    I don't see how this could be used though, nor do I see how you would reference any properties, unless you set the function = to an object within its self. (That could be useful)

    Brewguru99

  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: ME.?

    If your aim is to use the nNewVal that is inside the fn F1 say something like
    f2(nNewVal). If you want the parameters (modified/unmodified) of one function .. call the other fn from this function!, passing all the params.

    And what you are doing is not allowed in VB. If you are thinking of trying "Function pointers of C" ( - from your example i dont think you are!!), it is not allowed from VB-VB calls.

    And FUNCTIONS are not OBJECTS. Objects may contain (member) functions !!

    RK

  4. #4
    Join Date
    Jul 1999
    Posts
    145

    Re: ME.?

    You can pass a procedure pointer with vb but I don't know what you'd do with it once you had it except for ship it off to an API.
    Compliments of Bruce McKinney "Hardcore VB":

    Function GetProc(proc as Long) as Long

    GetProc= proc

    End Function

    then call the function like this:

    procWindow =GetProc(AddressOf EnumWndProc)

    or whatever procedure pointer you wanted.

    Not really a solution to the question here but kind of a neat trick huh


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

Featured