Announcement

Collapse
No announcement yet.

Using a Codeptr instead of Function name when adding DDT control?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • jcfuller
    replied
    Mike,
    I forgot to mention that I have code so you can roll your own Dialogs at
    run time. I use it with a script engine I created. If you're interested email
    me at mailto:[email protected][email protected]</A>

    James


    ------------------




    [This message has been edited by jcfuller (edited June 29, 2000).]

    Leave a comment:


  • Mike Joseph
    replied
    Thanks guys.

    ------------------

    Leave a comment:


  • Eric Pearson
    replied
    Mike --

    The CONTROL ADD function does not support CALL DWORD, in part (I would speculate) because you must use a special CALLBACK function, not just any old function. And since the compiler has no way of knowing whether or not your lFunc points to a CALLBACK function or a regular function...

    Your best bet is probably to simulate the effect you're looking for, by using an IF/THEN block inside your CALLBACK FUNCTION. This is only pseudo-code, but I'm picturing something like this:

    Code:
    Callback Function MasterCallback() as long
      
        DIM dwFunc1 AS GLOBAL DWORD
     
        IF CBCTL = %CTL_ID THEN
        	CALL DWORD dwFunc1 USING (...) CBHNDL, CBCTL, CBWPARAM, CBLPARAM
        ELSEIF CBCTL = %etc.
            CALL DWORD etc.
        ELSEIF...
            etc.
        END IF
     
    End Function
     
    Sub TryIt()
        DIM dwFunc1 AS GLOBAL DWORD
        dwFunc1 = CODEPTR(Test)
        CONTROL ADD BUTTON, hWin, %CTL_ID, "Caption", _
                            x,y,xx,yy, 0, CALL MasterCallback
    End Sub
    If you want to keep things organized, instead of using separate variables like dwFunc1 I'd suggest using a two-dimensional DWORD array, where the first column stores the %CTL_ numbers and the second column stores the CODEPTR values. Better yet, use a single-dimension DWORD array to store the CODEPTR values, and use %CTL_ID = 1, etc. so that the control numbers themselves tell you which array element to use...

    Code:
    Callback Function MasterCallback() as long
      
        DIM dwFunc() AS GLOBAL DWORD
     
        CALL DWORD dwFunc(CBCTL) USING(...) CBHNDL,CBCTL,CBWPARAM,CBLPARAM TO lResult
    
        FUNCTION = lResult
     
    End Function
    -- Eric


    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited June 27, 2000).]

    Leave a comment:


  • jcfuller
    replied
    Mike,
    The way I would handle it is to use a common callback function for
    all your controls and from there use CALL DWORD with the CODEPTR of the
    function you want.

    James


    ------------------

    Leave a comment:


  • Using a Codeptr instead of Function name when adding DDT control?

    Hi. I'm wondering if its possible to use a Codeptr instead of a function name when adding a DDT control?

    e.g.
    Code:
    Callback Function Test() as long
         Msgbox "hi"
    End FUnction
    
    Sub TryIt()
         lFunc = CODEPTR(Test)
         CONTROL ADD BUTTON, hWin, %CTL_ID, "Caption", _
         x,y,xx,yy, 0, CALL lFunc
    End Sub
    When I run the above, i get an error "undefined label/line reference" Any ideas? The reason I need to do this is because my controls need to be created dynamically from a script and the specific call back function to be used for a particular button is also specified in the script.

    -Mike

    [This message has been edited by Mike Joseph (edited June 27, 2000).]
Working...
X