Seria possível mudar o método "Aevalwhen" de WINDOW.PRG para trabalhar com FOR EACH de xharbour ? Veja um exemplo abaixo:
- Code: Select all Expand view RUN
#include "FiveWin.ch"
function Main()
local oDlg, cName := Space( 10 )
DEFINE DIALOG oDlg TITLE "Testing ForEach for speed"
@ 1, 2 SAY "Name:"
@ 1, 7 GET cName
@ 2, 5 BUTTON "AEvalWhen() of FWH" ACTION FWH_EVAL( oDlg )
@ 3, 5 BUTTON "My AEvalWhen()" ACTION MY_EVAL( oDlg )
ACTIVATE DIALOG oDlg
return nil
function FWH_EVAL( oDlg )
local x, nStart
nStart := Seconds()
for X = 1 to 100000
oDlg:AEvalWhen()
next
msgstop( Seconds() - nStart )
return NIL
//----------------------------------------------------------------------------//
function MY_EVAL( oDlg )
local n
local aControls := oDlg:aControls, aVarray
local x, nStart
nStart := Seconds()
for X = 1 to 100000
if aControls != nil .and. ! Empty( aControls )
for each aVarray IN oDlg:aControls
if aVarray != nil .and. aVarray:bWhen != nil
if Eval( aVarray:bWhen )
aVarray:Enable() // keep this as ::
else
aVarray:Disable() // keep this as ::
endif
endif
next
endif
next
msgstop( Seconds() - nStart )
return NIL
* Extract from WINDOW.PRG
*METHOD AEvalWhen() CLASS TWindow
* local n
* local aControls := ::aControls, aVarray
*
* if aControls != nil .and. ! Empty( aControls )
* for each aVarray IN ::aControls
* if aVarray != nil .and. aVarray:bWhen != nil
* if Eval( aVarray:bWhen )
* aVarray:Enable() // keep this as ::
* else
* aVarray:Disable() // keep this as ::
* endif
* endif
* next
** for n = 1 to Len( aControls )
** if aControls[ n ] != nil .and. aControls[ n ]:bWhen != nil
** if Eval( aControls[ n ]:bWhen )
** ::aControls[ n ]:Enable() // keep this as ::
** else
** ::aControls[ n ]:Disable() // keep this as ::
** endif
** endif
** next
* endif
*return nil
Executando o exemplo acima em meu computador o tempo fica assim:
Clicando em "AEvalWhen() of FWH" gasta o tempo de 1.203 segundos
Clicando em "My AEvalWhen()" gasta o tempo de 0.625 segundos, ou seja quase a metade do tempo
Obrigado,
Rossine.