Página 1 de 1

access objects from a function

Publicado: Mié Jul 08, 2009 11:14 am
por Ron Broere
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

access objects from a function

Publicado: Mié Jul 08, 2009 11:29 am
por Xailer
Hello Ron
To keep your function simple add a third parameter
something like this :
STATIC FUNCTION DIR_RECURS( cPath, cMask,oForm)
If your form is the main application form you can have access on it simply
call Application:oMainForm:anyObjectInstance or
passing self as third parameter.
now in your function you need to do something like this
> oForm:oLabel3:lVisible := .t.
Hope this can help you
Best Regards
Dionisis
"Ron Broere" <ronbroere@bbkm.nl> wrote in message
news:4a54636a$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
> 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
>
>

access objects from a function

Publicado: Mié Jul 08, 2009 11:29 am
por Xailer
Hello Ron
To keep your function simple add a third parameter
something like this :
STATIC FUNCTION DIR_RECURS( cPath, cMask,oForm)
If your form is the main application form you can have access on it simply
call Application:oMainForm:anyObjectInstance or
passing self as third parameter.
now in your function you need to do something like this
> oForm:oLabel3:lVisible := .t.
Hope this can help you
Best Regards
Dionisis
"Ron Broere" <ronbroere@bbkm.nl> wrote in message
news:4a54636a$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
> 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
>
>

access objects from a function

Publicado: Mar Jul 14, 2009 9:39 am
por Ron Broere
thank you! perfect.
"Dionisis Divaris" <info@sgs-soft.gr> wrote in message
news:[email=4a5466e9@svctag-j7w3v3j....]4a5466e9@svctag-j7w3v3j....[/email]
> Hello Ron
>
> To keep your function simple add a third parameter
> something like this :
> STATIC FUNCTION DIR_RECURS( cPath, cMask,oForm)
>
> If your form is the main application form you can have access on it
> simply call Application:oMainForm:anyObjectInstance or
> passing self as third parameter.
> now in your function you need to do something like this
>> oForm:oLabel3:lVisible := .t.
>
> Hope this can help you
> Best Regards
> Dionisis
>
> "Ron Broere" <ronbroere@bbkm.nl> wrote in message
> news:4a54636a$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
>> 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
>>
>>
>
>

access objects from a function

Publicado: Mar Jul 14, 2009 9:39 am
por Ron Broere
thank you! perfect.
"Dionisis Divaris" <info@sgs-soft.gr> wrote in message
news:[email=4a5466e9@svctag-j7w3v3j....]4a5466e9@svctag-j7w3v3j....[/email]
> Hello Ron
>
> To keep your function simple add a third parameter
> something like this :
> STATIC FUNCTION DIR_RECURS( cPath, cMask,oForm)
>
> If your form is the main application form you can have access on it
> simply call Application:oMainForm:anyObjectInstance or
> passing self as third parameter.
> now in your function you need to do something like this
>> oForm:oLabel3:lVisible := .t.
>
> Hope this can help you
> Best Regards
> Dionisis
>
> "Ron Broere" <ronbroere@bbkm.nl> wrote in message
> news:4a54636a$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
>> 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
>>
>>
>
>