Page 1 of 1
					
				Codeblocks and getlist
				Posted: Wed Feb 04, 2015 6:51 am
				by c-tec
				Hello, 
for creating pushbuttons in a for next loop I need the getlist as parameter. I tried this with detached locals, works, but the getlist is always a empty array. How can I get the getlist in myfunction 
regards
Rudolf
Code: Select all
for x := 1 to 10
     @ x,1 DCPUSHBUTTONXP caption ntrim(x) SIZE 10,10 ACTION makeblock(getlist,x)  // test 1
     @ x,1 DCPUSHBUTTONXP caption ntrim(x) SIZE 10,10 ACTION &("{||myfunction(getlist," + ntrim(x) + ")}) // test 2
...
function makeblock(getlist,x)
******************************************************************
local cBlock := "myfunction(getlist," + ntrim(x) + ")"
return &("{||" + cBlock + "}")
function myfunction(aGetlist,x)
******************************************************************
*/
 
			
					
				Re: Codeblocks and getlist
				Posted: Wed Feb 04, 2015 7:49 am
				by c-tec
				Hello, 
problem solved, found a workaround
regards
Rudolf
Code: Select all
ACTION &("{|a,b,o|changecaption('" + "__" + FT_NAME  +  "',a,b,o)}")  
function changecaption(cID,a,b,o)
******************************************************************
local aGetlist := o:getlist:getlistarray
...
 
			
					
				Re: Codeblocks and getlist
				Posted: Wed Feb 04, 2015 8:39 am
				by rdonnay
				Rudolf -
The GetList should NOT be an empty array, unless you are using the EXIT clause of DCREAD GUI without using the SAVE clause.
Roger
			 
			
					
				Re: Codeblocks and getlist
				Posted: Fri Feb 06, 2015 10:26 pm
				by c-tec
				Hello Roger, 
both samples are leading to an empty getlist array, I think it has todo with detached locals, but how to pass it correct to the codeblock.
regards
Rudolf
Code: Select all
#include "dcdialog.ch"
// ---------------------------------------------------------------------------
proc dbesys ; return
// ---------------------------------------------------------------------------
proc main()
local getlist := {}
for x := 1 to 10
     *@ x,1 DCPUSHBUTTONXP caption ntrim(x) SIZE 20,1 ACTION makeblock(getlist,x)  // test 1
     @ x,1 DCPUSHBUTTON caption ntrim(x) SIZE 10,1 ACTION &("{||myfunction(getlist," + ntrim(x) + ")}") // test 2
next x
dcread gui fit
return .t.
function makeblock(getlist,x)
******************************************************************
local cBlock := "myfunction(getlist," + ntrim(x) + ")"
return &("{||" + cBlock + "}")
function myfunction(aGetlist,x)
******************************************************************
dc_arrayview(aGetlist)
return
function ntrim(x)
return str(x,0)
 
			
					
				Re: Codeblocks and getlist
				Posted: Sat Feb 07, 2015 1:33 pm
				by rdonnay
				You need to use code blocks to create detached locals.  Don't try to do this with a macro.
Run this code:
Code: Select all
#include "dcdialog.ch"
// ---------------------------------------------------------------------------
proc dbesys ; return
// ---------------------------------------------------------------------------
Function main()
local getlist := {}, x
for x := 1 to 10
   @ x,1 DCPUSHBUTTONXP caption Alltrim(Str(x)) SIZE 20,1 ACTION makeblock(getlist,x)  // test 1
next x
dcread gui fit
return .t.
* ----------
function makeblock(getlist,x)
return {||MyFunction(GetList,x)}
* ----------
function myfunction(aGetlist,x)
MsgBox( 'You pushed button ' + Alltrim(Str(x)))
dc_arrayview(aGetlist)
return
 
			
					
				Re: Codeblocks and getlist
				Posted: Sun Feb 08, 2015 3:44 am
				by c-tec
				Hello Roger,
thank you ! works now. 
regards
Rudolf