News

How to execute a ‘parallel’ procedure in a VFP application

Sometimes it is necessary to call an object that will process certain information and has a considerable process’ time. For example, if you have a set of invoices that are shown in the work panel, you must choose a set of them to print them.

Sometimes it is necessary to call an object that will process certain information and has a considerable process’ time.
For example, if you have a set of invoices that are shown in the work panel, you must choose a set of them to print them. This means that a procedure that goes over the ‘marked’, and prints them will be called. The code would be something similar to:

Event enter
  
For each line
     
If &Marked=’S’
         
Call(pmark) // this object marks the invoice as pending to be printed 
      
Endif
     
&Marked=’N’
  
endfor
  
call(pprint)
endevent

In the example, the application’s user will have to wait for the ‘pprint’ to end the printing before he can continue using the application.

In order to avoid the user’s waiting, what can be done is:

  • Defining the procedure as Main (EXE) 
  • Substituting the ‘call(pprint)’ by ‘DBASE ! aprint’

By doing it this way, another VFP window is opened and the procedure runs independently, leaving the caller free.

Another way of doing it is declaring it as a main and substituting the call by the following:

DBASE RUN/N aprint.exe

The RUN executes the procedure leaving the caller ‘free’, and the /N avoids another window to be opened.

NOTE: Remember that if an object is main the first letter changes. In the example, the procedure is ‘P’ but when being main it changes to ‘A’. The EXE’s name must be included.