Array of gets

Post Reply
User avatar
Rimantas
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Array of gets

Post 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 !
Rimantas U.
User avatar
Rimantas
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: Array of gets

Post 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 !
Rimantas U.
User avatar
Rimantas
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: Array of gets

Post 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 !
Rimantas U.
Frank Demont
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Post 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
User avatar
Rimantas
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Post 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 !
Rimantas U.
User avatar
Rimantas
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Post 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 !
Rimantas U.
Frank Demont
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Post 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
User avatar
Rimantas
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Post 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 .
Rimantas U.
Goran Papic
Posts: 3
Joined: Thu Oct 27, 2005 1:31 pm
Location: Sisak, Croatia

FOR ... GET ...NEXT

Post 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
User avatar
Rimantas
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: FOR ... GET ...NEXT

Post 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 !
Rimantas U.
Marc Boissinot
Posts: 6
Joined: Thu Oct 13, 2005 3:41 pm
Location: Quebec City, Canada

Post 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 ) }
User avatar
Rimantas
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Post 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 .
Rimantas U.
Post Reply