Array of gets

Array of gets

Postby Rimantas » Wed Oct 26, 2005 7:07 am

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

Postby Rimantas » Wed Oct 26, 2005 10:30 am

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

Postby Rimantas » Wed Oct 26, 2005 11:49 am

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

Postby Frank Demont » Wed Oct 26, 2005 2:32 pm

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

Postby Rimantas » Thu Oct 27, 2005 5:00 am

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

Postby Rimantas » Thu Oct 27, 2005 7:41 am

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

Postby Frank Demont » Thu Oct 27, 2005 8:19 am

You can try :


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

or

FOR EACH xVal IN hHash:Values
? xVal
NEXT
Frank Demont
 
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Postby Rimantas » Thu Oct 27, 2005 9:04 am

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

FOR ... GET ...NEXT

Postby Goran Papic » Fri Oct 28, 2005 9:27 am

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

Re: FOR ... GET ...NEXT

Postby Rimantas » Fri Oct 28, 2005 12:59 pm

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

Postby Marc Boissinot » Fri Oct 28, 2005 1:29 pm

Here's a way with the detached local method...

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


function ArrayGetBlock(aGets,i)

return { | u | If( PCount()==0, aGets[i], aGets[i]:= u ) }
Marc Boissinot
 
Posts: 6
Joined: Thu Oct 13, 2005 3:41 pm
Location: Quebec City, Canada

Postby Rimantas » Mon Oct 31, 2005 5:43 pm

Marc Boissinot wrote:Here's a way with the detached local method...

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


function ArrayGetBlock(aGets,i)

return { | u | If( PCount()==0, aGets[i], aGets[i]:= 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.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Otto and 42 guests