Page 1 of 1

Array of gets

Posted: Wed Oct 26, 2005 7:07 am
by Rimantas
Hi !

I want to assign gets in for .. next . Here is a small sample :

local oGets[ len( aFlds ) ]
...
for nGt := 1 to len( aFlds )
cFld := aFlds[ nGt ]
@ nRw, nCol GET oGets[ nGt ] VAR aGets[ nGt ] PICTURE aPct[ nGt ] PIXEL SIZE nSz, nFh VALID n_pas( cAlias, cFld )
next

It seems that this isn't working .. :-(( I remmember something about deattached locals , but at this moment i can't to find about them . Thanks in advance for any help !

With best regards !

Re: Array of gets

Posted: Wed Oct 26, 2005 10:30 am
by Rimantas
Rimantas wrote: local oGets[ len( aFlds ) ]
...
for nGt := 1 to len( aFlds )
cFld := aFlds[ nGt ]
@ nRw, nCol GET oGets[ nGt ] VAR aGets[ nGt ] PICTURE aPct[ nGt ] PIXEL SIZE nSz, nFh VALID n_pas( cAlias, cFld )
next

It seems that this isn't working .. :-(( I remmember something about deattached locals , but at this moment i can't to find about them .
Alreday found samples for that - testarr4.prg and tesloop.prg . But I have an problem with bValid for oGets arrays . My function n_pas( cAlias, cFld ) get an lats cFld value . How it make true ? One solution it can be at oDlg close moment , but I want to do that in oGet stage .

With best regards !

Re: Array of gets

Posted: Wed Oct 26, 2005 11:49 am
by Rimantas
Rimantas wrote: Alreday found samples for that - testarr4.prg and tesloop.prg . But I have an problem with bValid for oGets arrays . My function n_pas( cAlias, cFld ) get an lats cFld value . How it make true ? One solution it can be at oDlg close moment , but I want to do that in oGet stage
All is workig OK . Simply create codeblock

local bCdb := { |oGet, nGt, others params...| get_blc( oGet, nGt, other params ..) }

Now in the loop evaluate codeblock

for nGt := 1 to len( aFlds )
oGet[ nGt ] = eval( bCdb, oGet[ nGt ], nGt, other params )
next

mine get_blc function :

static function get_blc( oDlg, oGt, cAlias, cFld, nGt, aGet, cPict, nRow, nCol )

oGt := TGet():New( nRow, nCol, GenLocalBlock( aGet, nGt ), oDlg,,, cPict,,,,,,, .t. )

if fieldtp( cAlias, cFld ) == "C"
oGt:bValid := { |oGet| n_pas( cAlias, cFld,, oGet:Value(), .t. ) }
endif
return( oGt )

static function GenLocalBlock( aGet, n )
return bSETGET( aGet[ n ] )

Now all is working OK ! With best regards !

Posted: Wed Oct 26, 2005 2:32 pm
by Frank Demont
Why not using hash arrays ?
They are very usefull for building dialog's , also afterwards when they must be referenced in another get

LOCAL oGets := Hash()
LOCAL aPct := Hash()
for nGt := 1 to len( aFlds )
cFld := aFlds[ nGt ]
@ nRw, nCol GET oGets[ cFld ] VAR aGets[ nGt ] PICTURE aPct[ cFld ] PIXEL SIZE nSz, nFh VALID n_pas( cAlias, cFld )
next



Frank

Posted: Thu Oct 27, 2005 5:00 am
by Rimantas
Frank Demont wrote:Why not using hash arrays ?
They are very usefull for building dialog's , also afterwards when they must be referenced in another get

LOCAL oGets := Hash()
LOCAL aPct := Hash()
for nGt := 1 to len( aFlds )
cFld := aFlds[ nGt ]
@ nRw, nCol GET oGets[ cFld ] VAR aGets[ nGt ] PICTURE aPct[ cFld ] PIXEL SIZE nSz, nFh VALID n_pas( cAlias, cFld )
next
Frank , very good sample ! I'm using hash , but in that way - no so much brains :-) . Many thanks to you !

With best regards !

Posted: Thu Oct 27, 2005 7:41 am
by Rimantas
Rimantas wrote: Frank , very good sample ! I'm using hash , but in that way - no so much brains :-) . Many thanks to you !
This isn't working Frank ... :-( . I tried that . Simply add MsgInfo() to valid clause
@ CRow( 0 ), nCl GET oGets[ cFld ] VAR aGets[ cFld ] PICTURE aPct[ cFld ] PIXEL VALID ( MsgInfo( aGets[ cFld ] + " ; " + cFld ), ;
n_pas( ::aAlias[ ::nFld ], cFld,, aGets[ cFld ], .t. ) )

I did hash'es all clauses : oGets , aPct, aGets . But validation will receive only the last cFld . Have you ideas , how to nake to work this ?

With best regards !

Posted: Thu Oct 27, 2005 8:19 am
by Frank Demont
You can try :


FOR EACH xKey in hHash:Keys
? xKey, hHash[ xKey ]
NEXT

or

FOR EACH xVal IN hHash:Values
? xVal
NEXT

Posted: Thu Oct 27, 2005 9:04 am
by Rimantas
Frank Demont wrote:You can try :

FOR EACH xKey in hHash:Keys
? xKey, hHash[ xKey ]
NEXT

or

FOR EACH xVal IN hHash:Values
? xVal
NEXT
Tried , the same result ... :-( . The first get receive the last get's parameter .

FOR ... GET ...NEXT

Posted: Fri Oct 28, 2005 9:27 am
by Goran Papic
I had a same problem in FW1.9.2 and I solved it by replacing aGets array with vars:

for nGt := 1 to len( aFlds )
cFld := aFlds[ nGt ]
xVar="x"+strzero(nGt,3)
@ nRw, nCol GET oGets[ nGt ] VAR &xVar .....
next

I hope that it works in FW for Harbour too.

Regards

Goran

Re: FOR ... GET ...NEXT

Posted: Fri Oct 28, 2005 12:59 pm
by Rimantas
Goran Papic wrote:I had a same problem in FW1.9.2 and I solved it by replacing aGets array with vars:

for nGt := 1 to len( aFlds )
cFld := aFlds[ nGt ]
xVar="x"+strzero(nGt,3)
@ nRw, nCol GET oGets[ nGt ] VAR &xVar .....
next

I hope that it works in FW for Harbour too
Yes Goran , your sample is working in that way , I know . I used in early something similar . Simply it's interesting to do in others ways , like Frank's sample with hashes :-) .

With best regards !

Posted: Fri Oct 28, 2005 1:29 pm
by Marc Boissinot
Here's a way with the detached local method...

for i := 1 to Len( aGets )
@i,0 GET oGets VAR aGets
oGets:bSetGet := oGets:oGet:Block := ArrayGetBlock(aGets,i)
next


function ArrayGetBlock(aGets,i)

return { | u | If( PCount()==0, aGets, aGets:= u ) }

Posted: Mon Oct 31, 2005 5:43 pm
by Rimantas
Marc Boissinot wrote:Here's a way with the detached local method...

for i := 1 to Len( aGets )
@i,0 GET oGets VAR aGets
oGets:bSetGet := oGets:oGet:Block := ArrayGetBlock(aGets,i)
next


function ArrayGetBlock(aGets,i)

return { | u | If( PCount()==0, aGets, aGets:= u ) }


Hello Marc !

I'm using that "deatached" . Also I'm using codeblock to check validation of my vars . Evaluting of that works fine for array of gets . From codeblock it's direction to deatached function .

With best regards ! Rimantas .