![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
Generating ReportsWhen the ReportList client invokes the report servers LoadReport subroutine, control passes to the server. The server activates a timer control to trigger the actual report generation later, and it quickly returns control to the client. This allows the client to continue operating asynchronously. Scheduling the ReportAt this point, control passes to the server objects LoadReport subroutine. In the Query Server application, LoadReport creates the report and returns the results. The new version saves the parameters and callback object for later use, and it creates a WakeUpForm object. This form contains a single timer control named Waker. LoadReport enables Waker and then exits, returning control to the client application. Public Sub LoadReport(params As String, cb As Object) Save the callback object. Set TheCallback = cb Save the parameter string. TheParams = params Create a new WakeUpForm. Set TheWakeUpForm = New WakeUpForm Tell it what report to wake up. Set TheWakeUpForm.ReportObject = Me Activate the timer. TheWakeUpForm.Waker.Enabled = True End Sub Now the client application has finished requesting the report. Because it has no code running, the client becomes idle. The user could request a new report and begin entering parameter values on a ParameterForm. The user could also invoke a menu command or close a previously generated report. Something rather odd occurs if the user exits the application at this point. When the report server finishes creating the report, it invokes a callback object to display the results. If the client application has exited, the callback will still create a new form to display the report. Building that form will force the application to reopen the main MDI form so the report results can lie inside it. The MDI forms Load event then causes the ReportListForm to present a list of available reports. This behavior is decidedly strange. In other applications things might be even worse. For example, if the MDI forms Load event required the user to enter a user name and password, the program could enter a very strange state. The report results might still appear, even though the application would not necessarily be logged in as the same user. One way to prevent this sort of behavior would be to disable the Exit command as long as a server request was still running. When no such requests were outstanding, the Exit command would behave normally. Starting the Report ObjectWakeUpForm contains a single timer control named Waker. It also declares a form-level variable, Report-Object. The LoadReport subroutine described in the previous section saves a reference to a report object in this variable. When its Timer event occurs, Waker invokes this objects MakeReport subroutine to produce the actual report. Public ReportObject As Object Private Sub Waker_Timer() Disable the timer so we dont trigger again. Waker.Enabled = False Wake up the report object. ReportObject.MakeReport End Sub Building the ReportThe first thing the Report objects MakeReport subroutine does is unload the WakeUpForm. As mentioned earlier, this is extremely important. A Visual Basic program will not stop as long as it has any form running. If this form is not unloaded, the server process will keep running even after the client has finished with it. The task manager application on the server computer can determine whether a rogue server is running invisibly. In Windows 95, pressing Ctrl-Alt-Del presents a list of running tasks. If a server appears in the list, it may need to be stopped manually. Figure 13.5 shows the Windows 95 task manager. It is important not to confuse a runaway server process with an instance of the Visual Basic development environment that is working with the server. The server project loaded into the development environment will be named AsyncServer - Microsoft Visual Basic [design] in the task list. If the program is running in the development environment, the last part of this name will be [run] instead of [design]. If a running server has been interrupted in the development environment, this last part will be [break]. In Figure 13.5 the highlighted task is an AsyncServer running normally as an independent executable program. The top line shows the AsyncServer program running in the Visual Basic development environment. In Windows NT, double-clicking on the server computers screen background will bring up a task manager similar to the one shown in Figure 13.6. This task manager can also stop a runaway server. After unloading the WakeUpForm, MakeReport must produce the actual report. The report parameters were stored in class variable TheParams by the LoadReport subroutine that created the WakeUpForm object.
Once the report is finished, MakeReport invokes the callback objects DisplayReport subroutine to transfer the results back to the ReportList client application.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.
|