Dynamic Actions problem
Posted: Mon Jan 07, 2013 5:12 pm
Hi to all,
I have a problem using dynamic actions.
I hope someone can help me to solve the problem.
I usually create dynamic programs where the components are stored in arrays.
Here is an example:
The procedures in the aTest array could change depending on parameters passed to the procedure.
The caption is taked correctly from the array, the action not!
I would like that pressing the Msg1 button the message would be "1" and not Len(aTest)+1.
I have tried using "&(aTest[nN,2])", which should solve the action at creation time of the component, but I notice that it solve the action at action time, when the variable is Len(aTest)+1.
Some solution?
Regards
I have a problem using dynamic actions.
I hope someone can help me to solve the problem.
I usually create dynamic programs where the components are stored in arrays.
Here is an example:
Code: Select all
***************************************************************************
#include "hmg.ch"
FUNCTION Main()
DEFINE WINDOW Win1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 300 ;
TITLE 'Test Dynamic Actions from Array' ;
MAIN
DEFINE MAIN MENU
POPUP "Test"
MENUITEM "Test Dynamic Actions" ACTION TestButtons(7)
END POPUP
END MENU
DEFINE BUTTON TEST
ROW 10
COL 10
WIDTH 200
CAPTION 'Click Me!'
ACTION TestButtons(5)
END BUTTON
END WINDOW
Center Window Win1
Activate Window Win1
RETURN NIL
*****************************************************************************
Procedure TestButtons(nNum)
*****************************************************************************
Local nMax:=20
Private nN, aTest:={}
For nN:=1 to nNum
AAdd(aTest,{'Msg'+AllTrim(Str(nN)),'MsgBox("'+AllTrim(Str(nN))+'")'})
Next
DEFINE WINDOW HDWin ;
AT 0,0 ;
WIDTH 200 ;
HEIGHT 0 ;
TITLE 'Test!' ;
MODAL
For nN:=1 to Len(aTest)-1
nMax:=24*(nN-1)
DEFINE BUTTON &("B"+AllTrim(Str(nN)))
ROW 10+nMax
COL 10
WIDTH HDWin.WIDTH-20
Height 22
CAPTION aTest[nN,1]
// ACTION &("aTest[nN,2]") // <<<<<<<<<<<< With this the procedure return nN variable error
// ACTION &("aTest["+AllTrim(Str(nN))+",2]") // <<<<<<<<<<< With this the procedure do nothing!
// ACTION aTest[nN,2] // <<<<<<<<<<< With this the procedure do nothing!
// ACTION MsgBox(aTest[nN,2]) // <<<<<<<<<<< With this the procedure always return Len(aTest)+1!!!
ACTION MsgBox(Str(nN)) // <<<<<<<<<<< With this the procedure always return Len(aTest)+1!!!
END BUTTON
Next
HDWin.Height:=nMax+40+GetTitleHeight()+GetBorderHeight()
END WINDOW
CENTER WINDOW HDWin
ACTIVATE WINDOW HDWin
Return
***********************************************************************************
The caption is taked correctly from the array, the action not!
I would like that pressing the Msg1 button the message would be "1" and not Len(aTest)+1.
I have tried using "&(aTest[nN,2])", which should solve the action at creation time of the component, but I notice that it solve the action at action time, when the variable is Len(aTest)+1.
Some solution?
Regards