onProgress example
Suppose you want to rebuild an index tag as part of a table maintenance feature, and while it’s working, display progress information in a form. You could create a form with a Progress control to display the percentage complete and a Text control for messages. Here are the two pertinent form methods:
function Form_onOpen
_app.session.onProgress = class::onProgress
_app.session.form = form
index on LAST_NAME + FIRST_NAME tag FULL_NAME
_app.session.onProgress = null
function onProgress( nPercent, msg )
if nPercent >= 0
this.form.progress1.value = nPercent
elseif not empty( msg )
this.form.message1.text = msg
endif
By using an onOpen event, everything happens simply by opening the form. First, the onProgress( ) method in the form is assigned as the onProgress event handler for the _app object’s session. Then a reference to the current form is assigned as a property of the session so that the session’s event handler can easily access the form. Then the actual indexing is performed, and when it’s done, the onProgress event is cleared by assigning null.
In the onProgess( ) method, the nPercent parameter is checked. If it’s greater than zero, the method is being passed an updated percentage, so the Progress control is updated. Otherwise, if the msg parameter is not blank, its contents are displayed in the Text control on the form.