<< Click to Display Table of Contents >> Generating a Document while the Preview is open |
This section describes the technique of generating a report asynchronous to an open preview without multi-threading.
"Asynchronous preview" means that your application is still creating a report (i.e. adding objects and pages), while the preview is already open and the user may scroll through the document.
To make this possible, VPE uses internally two pages:
•one that is shown in the preview (called VisualPage)
•and one your application can work with, i.e. insert objects like text, bitmaps, etc. (called CurrentPage)
General Implementation:
•Open the document with OpenDoc
•Open the Preview with Preview()
•Do output calls and call DispatchAllMessages() regularly. DispatchAllMessages() allows VPE to do necessary updates in the preview, to react onto user actions and to send messages to your application. In other words: it keeps the preview AND your application "alive".
•Check the return value of DispatchAllMessages(). If it returns TRUE, the preview or the parent window of the preview are closed by the user: so perform the necessary cleanup (for example close tables and databases) and exit the function that creates the report immediately.
NEVER CALL ANY VPE-Function if the document is not (or no longer) open!
NOTE: | If you insert objects on the VisualPage (that means, VisualPage = CurrentPage) with an open preview and you move the CurrentPage to another page, the updates in the preview become automatically visible. Otherwise you need to call the method Refresh (DLL: VpeRefreshDoc), to make the changes visible in the preview. |
Example:
OpenDoc()
Preview()
for n = 1 to 1000
while objects to insert on CurrentPage
... insert objects on the CurrentPage ...
if DispatchAllMessages() = True then
exit this function
end if
end while
PageBreak()
next n
In the example above, the method DispatchAllMessages() is called periodically, so the preview and the calling application can react onto user action (keeps "alive").
For a complete example, please take a look at the provided demo source codes. The technique described here is used in the "Speed + Tables" demo.