access objects from a function
Publicado: Mié Jul 08, 2009 11:14 am
How can I access the form or object from a function?
In the example I have a recursive function to delete files with a certain
extension. I want to make a progress bar on the form, but from within the
function I cannot access the form or the application or any object. Should I
convert the function to a method? How?
Example:
//---------------------------------------------------------- --------------------
STATIC FUNCTION DIR_RECURS( cPath, cMask)
local x, aFiles, nFilCount
aFiles := directory( cPath + '*.*', 'D' )
nFilCount := len( aFiles )
for x := 1 to nFilCount
if aFiles[ X, F_NAME ] <> '..'
// it is a file,
// do we want to delete it?
IF right( aFiles[ X, F_NAME ],3) == cMask
IF FERASE( cPath + "" + aFiles[ X, F_NAME ])
nResult++
// updating the form does not work from inside this function
// NO SELF
::oLabel3:lVisible := .t.
//
ENDIF
ENDIF
endif
if 'D' $ aFiles[ X, F_ATTR ]
if aFiles[ X, F_NAME ] <> '.'
DIR_RECURS( cPath + '' + aFiles[ X, F_NAME ], cMask )
endif
endif
next
RETURN NIL
In the example I have a recursive function to delete files with a certain
extension. I want to make a progress bar on the form, but from within the
function I cannot access the form or the application or any object. Should I
convert the function to a method? How?
Example:
//---------------------------------------------------------- --------------------
STATIC FUNCTION DIR_RECURS( cPath, cMask)
local x, aFiles, nFilCount
aFiles := directory( cPath + '*.*', 'D' )
nFilCount := len( aFiles )
for x := 1 to nFilCount
if aFiles[ X, F_NAME ] <> '..'
// it is a file,
// do we want to delete it?
IF right( aFiles[ X, F_NAME ],3) == cMask
IF FERASE( cPath + "" + aFiles[ X, F_NAME ])
nResult++
// updating the form does not work from inside this function
// NO SELF
::oLabel3:lVisible := .t.
//
ENDIF
ENDIF
endif
if 'D' $ aFiles[ X, F_ATTR ]
if aFiles[ X, F_NAME ] <> '.'
DIR_RECURS( cPath + '' + aFiles[ X, F_NAME ], cMask )
endif
endif
next
RETURN NIL