Execute From Pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pachydermitis

    #1

    Execute From Pointer

    Hi,
    Is there any way to execute a function by using it's pointer?
    The reason I want to do this is: I have a control on a form that I
    have wrapped with a class. I want to be able to dynamically assign a
    function that is in the form's code to an event defined in the wrapper
    class. The application.run function won't recognise the name of the
    function in a form (at least I don't know how to make it so). e.g.
    Applicaion.Run "Form_fMyForm.M yFunction" So I thought that pointer to
    the function might work - if I could figure out how to execute the
    function using it's address.
    Thanks in advance
    Pachydermitis

  • Tom van Stiphout

    #2
    Re: Execute From Pointer

    On 6 Nov 2006 18:07:45 -0800, "Pachydermi tis" <praesagus@gmai l.com>
    wrote:

    Not by pointer (unless you would consider AddressOf, an advanced
    topic), but by name: check out the Eval function.

    -Tom.

    >Hi,
    >Is there any way to execute a function by using it's pointer?
    >The reason I want to do this is: I have a control on a form that I
    >have wrapped with a class. I want to be able to dynamically assign a
    >function that is in the form's code to an event defined in the wrapper
    >class. The application.run function won't recognise the name of the
    >function in a form (at least I don't know how to make it so). e.g.
    >Applicaion.R un "Form_fMyForm.M yFunction" So I thought that pointer to
    >the function might work - if I could figure out how to execute the
    >function using it's address.
    >Thanks in advance
    >Pachydermiti s

    Comment

    • MGFoster

      #3
      Re: Execute From Pointer

      Pachydermitis wrote:
      Hi,
      Is there any way to execute a function by using it's pointer?
      The reason I want to do this is: I have a control on a form that I
      have wrapped with a class. I want to be able to dynamically assign a
      function that is in the form's code to an event defined in the wrapper
      class. The application.run function won't recognise the name of the
      function in a form (at least I don't know how to make it so). e.g.
      Applicaion.Run "Form_fMyForm.M yFunction" So I thought that pointer to
      the function might work - if I could figure out how to execute the
      function using it's address.
      Thanks in advance
      Pachydermitis
      >
      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      The correct syntax is: Forms!FormName. FunctionName

      Try the Eval() function:

      strFunction = "Forms!myForm.F unctionName"
      Eval(strFunctio n)

      --
      MGFoster:::mgf0 0 <atearthlink <decimal-pointnet
      Oakland, CA (USA)
      ** Respond only to this newsgroup. I DO NOT respond to emails **

      -----BEGIN PGP SIGNATURE-----
      Version: PGP for Personal Privacy 5.0
      Charset: noconv

      iQA/AwUBRU/z4IechKqOuFEgEQ Io0ACg6Kt4eU1i5 DK98VGwBDZfq1vm gK0AoNJE
      hbxWd9uahJiNexN biH/mwQfv
      =yui4
      -----END PGP SIGNATURE-----

      Comment

      • Pachydermitis

        #4
        Re: Execute From Pointer

        I was counting on addressof for the function address, but once I have
        the pointer to a function, how do I execute it?
        Thanks
        P


        Tom van Stiphout wrote:
        On 6 Nov 2006 18:07:45 -0800, "Pachydermi tis" <praesagus@gmai l.com>
        wrote:
        >
        Not by pointer (unless you would consider AddressOf, an advanced
        topic), but by name: check out the Eval function.
        >
        -Tom.
        >
        >
        Hi,
        Is there any way to execute a function by using it's pointer?
        The reason I want to do this is: I have a control on a form that I
        have wrapped with a class. I want to be able to dynamically assign a
        function that is in the form's code to an event defined in the wrapper
        class. The application.run function won't recognise the name of the
        function in a form (at least I don't know how to make it so). e.g.
        Applicaion.Run "Form_fMyForm.M yFunction" So I thought that pointer to
        the function might work - if I could figure out how to execute the
        function using it's address.
        Thanks in advance
        Pachydermitis

        Comment

        • Pachydermitis

          #5
          Re: Execute From Pointer

          Thanks for the tip MG. I tried that but it did not work. It seems
          that eval, run and CallByName can not recognize methods of classes
          unless called within them.

          MGFoster wrote:
          Pachydermitis wrote:
          Hi,
          Is there any way to execute a function by using it's pointer?
          The reason I want to do this is: I have a control on a form that I
          have wrapped with a class. I want to be able to dynamically assign a
          function that is in the form's code to an event defined in the wrapper
          class. The application.run function won't recognise the name of the
          function in a form (at least I don't know how to make it so). e.g.
          Applicaion.Run "Form_fMyForm.M yFunction" So I thought that pointer to
          the function might work - if I could figure out how to execute the
          function using it's address.
          Thanks in advance
          Pachydermitis
          >
          -----BEGIN PGP SIGNED MESSAGE-----
          Hash: SHA1
          >
          The correct syntax is: Forms!FormName. FunctionName
          >
          Try the Eval() function:
          >
          strFunction = "Forms!myForm.F unctionName"
          Eval(strFunctio n)
          >
          --
          MGFoster:::mgf0 0 <atearthlink <decimal-pointnet
          Oakland, CA (USA)
          ** Respond only to this newsgroup. I DO NOT respond to emails **
          >
          -----BEGIN PGP SIGNATURE-----
          Version: PGP for Personal Privacy 5.0
          Charset: noconv
          >
          iQA/AwUBRU/z4IechKqOuFEgEQ Io0ACg6Kt4eU1i5 DK98VGwBDZfq1vm gK0AoNJE
          hbxWd9uahJiNexN biH/mwQfv
          =yui4
          -----END PGP SIGNATURE-----

          Comment

          • Lyle Fairfield

            #6
            Re: Execute From Pointer


            Pachydermitis wrote:
            Hi,
            Is there any way to execute a function by using it's pointer?
            The reason I want to do this is: I have a control on a form that I
            have wrapped with a class. I want to be able to dynamically assign a
            function that is in the form's code to an event defined in the wrapper
            class. The application.run function won't recognise the name of the
            function in a form (at least I don't know how to make it so). e.g.
            Applicaion.Run "Form_fMyForm.M yFunction" So I thought that pointer to
            the function might work - if I could figure out how to execute the
            function using it's address.
            Thanks in advance
            Pachydermitis
            Did you try

            Form_fMyForm.My Function

            ?

            This works for me for both a Sub and Function. One must remember to
            close the form afterward. The Function or Sub must be Public.

            I have been doing this since the last century. It works in standard
            modules.

            I have never needed eval although I remember someone posting a good use
            for it, I just don't remember the use.

            And yes, this works for a sub-form too. The notion of using the
            Form!Control.Fo rm etc etc obsolete syntax is pointless.

            I see you want to use it for a class event. Well, I'm not going to take
            the time to test that. But it works flawlessly in event procedures of
            another form, which are just classes with nice boobs anyway.

            Comment

            • Pachydermitis

              #7
              Re: Execute From Pointer

              Hey Lyle,
              What I actually need is to be able to execute a function that resides
              in a class and whose name I need to be able to change during runtime.

              dim sFunctionName as string
              sFunctionName ="MyFunction "
              application.run sFunctionName
              works well, as does Eval

              dim sFunctionName as string
              sFunctionName ="mMyClass.MyMe thod"
              application.run sFunctionName
              Does not

              I am having the same results with CallByName and Eval
              Hence my question as to how I can execute a proceedure using it's
              pointer.

              Thanks again all for your help
              P

              Lyle Fairfield wrote:
              Pachydermitis wrote:
              Hi,
              Is there any way to execute a function by using it's pointer?
              The reason I want to do this is: I have a control on a form that I
              have wrapped with a class. I want to be able to dynamically assign a
              function that is in the form's code to an event defined in the wrapper
              class. The application.run function won't recognise the name of the
              function in a form (at least I don't know how to make it so). e.g.
              Applicaion.Run "Form_fMyForm.M yFunction" So I thought that pointer to
              the function might work - if I could figure out how to execute the
              function using it's address.
              Thanks in advance
              Pachydermitis
              >
              Did you try
              >
              Form_fMyForm.My Function
              >
              ?
              >
              This works for me for both a Sub and Function. One must remember to
              close the form afterward. The Function or Sub must be Public.
              >
              I have been doing this since the last century. It works in standard
              modules.
              >
              I have never needed eval although I remember someone posting a good use
              for it, I just don't remember the use.
              >
              And yes, this works for a sub-form too. The notion of using the
              Form!Control.Fo rm etc etc obsolete syntax is pointless.
              >
              I see you want to use it for a class event. Well, I'm not going to take
              the time to test that. But it works flawlessly in event procedures of
              another form, which are just classes with nice boobs anyway.

              Comment

              • Pachydermitis

                #8
                Re: Execute From Pointer

                Ok, I'm a dork and did not read properly, here's how it works:

                dim sFunctionName as string
                dim cMyForm as Form_MyForm 'declared so we can explicitly destroy it
                set cMyForm =new Form_MyForm
                sFunctionName=" MyMethod"
                CallByName Form_MyForm, sFunctionName, VbMethod
                set cMyForm =nothing

                CallByName was specifically designed to answer this need.
                Thanks all
                P

                Comment

                • hbinc

                  #9
                  Re: Execute From Pointer

                  Hi Pachydermitis,

                  What I do is the following:
                  In any event on the I can add these statements:
                  ThisProcname = ....
                  Run ThisProcname, ThisForm
                  ThisProcname is composed dynamically, and results in the name of a
                  Public Sub.
                  Depending on situation ThisProcname (and so it behaviour) can be quite
                  different.

                  The Sub ThisProcname takes one argument: ThisForm, i.e. the Form on
                  which the event was fired. So the Sub knows exactly all the Controls
                  and their values (instead of using parameters) on the form.
                  In case you need a function-value: ThisProcname can leave a value in a
                  certain (invisible) control on ThisForm.

                  Regards, HBinc.



                  Pachydermitis schreef:
                  Hi,
                  Is there any way to execute a function by using it's pointer?
                  The reason I want to do this is: I have a control on a form that I
                  have wrapped with a class. I want to be able to dynamically assign a
                  function that is in the form's code to an event defined in the wrapper
                  class. The application.run function won't recognise the name of the
                  function in a form (at least I don't know how to make it so). e.g.
                  Applicaion.Run "Form_fMyForm.M yFunction" So I thought that pointer to
                  the function might work - if I could figure out how to execute the
                  function using it's address.
                  Thanks in advance
                  Pachydermitis

                  Comment

                  • Pachydermitis

                    #10
                    Re: Execute From Pointer

                    oops should be
                    CallByName cMyForm, sFunctionName, VbMethod

                    Pachydermitis wrote:
                    Ok, I'm a dork and did not read properly, here's how it works:
                    >
                    dim sFunctionName as string
                    dim cMyForm as Form_MyForm 'declared so we can explicitly destroy it
                    set cMyForm =new Form_MyForm
                    sFunctionName=" MyMethod"
                    CallByName Form_MyForm, sFunctionName, VbMethod
                    set cMyForm =nothing
                    >
                    CallByName was specifically designed to answer this need.
                    Thanks all
                    P

                    Comment

                    Working...