Page 1 of 1

get and codeblock

Posted: Thu Sep 22, 2016 8:09 am
by c-tec
Hello Roger
we just have a discussion in the german newsgroup, in this sample the value in the get is only changed when not using asize(0) and the add the values new to the array. Do you have an answer for this behaviour ? Not urgent, but would be interesting, I think it has to do with the reference to the array in the getlist.
regards
Rudolf

Code: Select all

procedure xtest()
LOCAL GetList:={}, arr:={}

aadd(arr,{"Karl ","Meier  "})

@ 02,01 dcsay {||arr[1,1]} saysize 0
@ 02,10 dcget arr[1,1]  // <----- does not change the value with fhein() und fewald()

@ 03,01 dcsay {||arr[1,2]} saysize 0
@ 03,10 dcget arr[1,2]  // <----- does not change the value with fhein() und fewald()

@ 05,01 dcbrowse ob1 data arr size 50,4 fit
dcbrowsecol element 1 header "Vorname" parent ob1 width 10
dcbrowsecol element 2 header "Name"    parent ob1 width 10

@ 12,0 dcpushbutton caption "Hein" size 10,1 ;
      action {||fhein(arr,getlist)}

@ 12,10 dcpushbutton caption "Ewald" size 10,1 ;
        action {||fewald(arr,getlist)}

@ 12,20 dcpushbutton caption "Hein 2" size 10,1 ;
      action {||fhein2(arr,getlist)}

@ 12,30 dcpushbutton caption "Ewald 2" size 10,1 ;
        action {||fewald2(arr,getlist)}


DCREAD GUI FIT

RETURN

function fhein(arr,aGetlist)
asize(arr,0)
aadd(arr,{"Hein","Mück"}) // not visible in get codeblock
dc_getrefresh(aGetlist)
return .t.

function fewald(arr,aGetlist)
asize(arr,0)
aadd(arr,{"Ewald ","Saur"}) // not visible in get codeblock
dc_getrefresh(aGetlist)
return .t.


function fhein2(arr,aGetlist)
arr[1,1] := "Hein"  // this way it works works
arr[1,2] := "Mück"
dc_getrefresh(aGetlist)
return .t.

function fewald2(arr,aGetlist)
arr[1,1] := "Müller"  // works
arr[1,2] := "Franz"   // works
dc_getrefresh(aGetlist)
return .t.

Re: get and codeblock

Posted: Fri Sep 30, 2016 8:49 am
by psc
This might have to do with the reference to the sub-array getting clobbered ( I think ).

Try this for fhein:

Code: Select all

function fhein(arr,aGetlist)
  local aFoo
  aFoo := arr[1]
  asize( arr , 0)
  aadd( arr , aFoo )
  asize( aFoo , 0 )
  aadd(aFoo,"Hein") 
  aadd(aFoo,"Mück") 
  dc_getrefresh(aGetlist)
  return .t.
This populates the get

psc

Re: get and codeblock

Posted: Fri Sep 30, 2016 3:32 pm
by rdonnay
Psc is correct that it is a pointer problem.

You are creating a new pointer to the variable whereas the Get is bound to the previous pointer.

This is how a code block is bound to the Get:
oGet:datalink := aGetListItem[bGETLIST_VAR]


When you create a GET, a function named DC_GetAnchorCB() is used to create the code block.

Try this:
cNewValue := 'Hein'

oGet:dataLink := DC_GetAnchorCB(cNewValue)

oGet:refresh()

Re: get and codeblock

Posted: Sat Oct 01, 2016 10:30 am
by c-tec
Hello Roger,
thank you, I thougt that dc_getanchorCB() could help, will try it this way.
regards
Rudolf