Using the value of the property Application.Busy of the class Application (gb. qt4), you change the 'Busy state' of an application.
Suggestion:
Apply a button to a form in an example project and include the following source code as an event handler to see the effect of using the Application.Busy property:
Public Sub btnSetBusy_Click() Dim iCount As Integer Inc Application.Busy ' Alternative: Application.Busy = 1 For iCount = 1 To 40000 Print Sqr(iCount + Pi(0.533)) Next ' iCount Dec Application.Busy ' Application.Busy = 0 Message.Info("That's all it was..") End
The examples serve to demonstrate the use of the control element Application. Busy in different applications.
Example 1
In an application for installing gambas via SVN, the local version number on the PC is first queried and then the number of the current revision on the SVN server. For this query, the program will use the mouse pointer to indicate the “Binary busy state” and will not respond to user input. If an error occurs, it is intercepted, an error message is issued and the program is released again with' Dec Application. Busy'. The release is also carried out if the revision number could be determined without errors.
Public Sub btnUpdateStart_Click() Dim sResult, sMessage As String Dim iTimeOut As Integer ' ... Inc Application.Busy ' Mouse.Wait Repeat Shell "cd " & sSVNPfad & "; svn info -r HEAD | awk '$1 ~ /^Revision:$/ {print $2;}'" To sResult Inc iTimeOut Until (sResult <> Null Or iTimeOut > 9) Try iSVNCurrentRevision = Val(sResult) If Error Then Message.Error("The SVN server is currently unavailable!") Dec Application.Busy Return Endif ' ERROR ? Dec Application.Busy ' Mouse.Default End ' btnUpdateStart_Click()
Figure 10.5.9.2.1: The queries were successful
Example 2
A print program does not accept any more entries in the time in which it is printed:
Public Sub btnPrintImage_Click() If printerImage.Configure() Then Return Me.Enabled = False ' The form is deactivated Application.Busy = 1 ' The program does not accept any more entries.. printerImage.Print ' The print job is started.. Application.Busy = 0 ' The program accepts input again.. Me.Enabled = True ' The form is reactivated End ' btnPrintImage_Click()
Example 3
As a sub-process for the installation of a program (update) from existing packages, the statement /configure -C is executed, which analyzes the system, configures the packages and generates the makefile. The main program ignores all entries for the runtime of the subprocess:
Public Sub btnConfigureUpdate_Click() Inc Application.Busy sShellCommand = "echo 'CONFIGURE';echo '---------------------------';" sShellCommand &= " cd " & sSVNPfad & ";./configure -C" GoToTerminal(GetTerminalList()[0], sShellCommand) btnMakeUpdate.Enabled = True Dec Application.Busy End
Example 4
For the Watcher class demonstration program (→ chapter 20.10 Watcher) the monitored events should be handled and documented with messages in separate windows. The following source code extract from the testing phase for the project caused not only errors, but also a program crash, because the constant change (move or resize) caused message windows to be generated:
Public Sub wWatcher_Resize() Message.Info(("The main window " & wWatcherObject1.Control.Name & " has changed its size!")) Stop Event End
Public Sub wWatcher_Move() Message.Info(("The main window " & wWatcherObject1.Control.Name & " has changed position!")) Stop Event End
The thoughts and approaches to the solution:
Here is the corrected section of the source code:
Private sControlName As String ' ... sControlName = "'" & wWatcherObject1.Control.Name & "'" ' ... Public Sub wWatcher_Resize() Application.Busy = 1 If Application.Busy = 1 Then Message.Info("The window " & sControlName & " has changed its size!") Application.Busy = 0 Stop Event End Public Sub wWatcher_Move() Inc Application.Busy If Application.Busy = 1 Then Message.Info("Das Fenster " & sControlName & " has changed position!") Dec Application.Busy Stop Event End
Über den Wert der Eigenschaft Application.Busy der Klasse Application (gb.qt4) ändern Sie den 'Beschäftigt-Zustand' einer Anwendung.
Vorschlag:
Spendieren Sie einem Formular in einem Beispiel-Projekt einen Button und fügen Sie den folgenden Quelltext als Ereignisbehandlungsroutine ein, um sich von der Wirkung der Verwendung der Eigenschaft Application.Busy zu überzeugen:
Public Sub btnSetBusy_Click() Dim iCount As Integer Inc Application.Busy ' Alternative: Application.Busy = 1 For iCount = 1 To 40000 Print Sqr(iCount + Pi(0.533)) Next ' iCount Dec Application.Busy ' Application.Busy = 0 Message.Info("Das war es auch schon ...") End ' btnSetBusy_Click()
Die Beispiele dienen der Demonstration des Einsatzes des Kontroll-Elements Application.Busy in unterschiedlicher Verwendung.
Beispiel 1
In einer Applikation für die Installation von Gambas über SVN wird zuerst die lokale Versionsnummer auf dem PC abgefragt und dann die Nummer der aktuellen Revision auf dem SVN-Server. Für diese Abfrage wird das Programm nach außen über den Mauszeiger den “Bin-beschäftigt-Zustand” signalisieren und nicht auf Benutzereingaben reagieren. Tritt ein Fehler auf, wird dieser abgefangen, eine Fehlermeldung ausgegeben und danach das Programm mit 'Dec Application.Busy' wieder freigegeben. Die Freigabe erfolgt auch dann, wenn die Revisionsnummer fehlerfrei ermittelt werden konnte.
Public Sub btnUpdateStart_Click() Dim sResult, sMessage As String Dim iTimeOut As Integer ' ... Inc Application.Busy ' Mouse.Wait Repeat Shell "cd " & sSVNPfad & "; svn info -r HEAD | awk '$1 ~ /^Revision:$/ {print $2;}'" To sResult Inc iTimeOut Until (sResult <> Null Or iTimeOut > 9) Try iSVNCurrentRevision = Val(sResult) If Error Then Message.Error("Der SVN-Server ist gegenwärtig nicht erreichbar!") Dec Application.Busy Return Endif ' ERROR ? Dec Application.Busy ' Mouse.Default End ' btnUpdateStart_Click()
Abbildung 10.5.9.2.1: Die Abfragen waren erfolgreich
Beispiel 2
Ein Druckprogramm nimmt in der Zeit, in der gedruckt wird, keine Eingaben mehr an:
Public Sub btnPrintImage_Click() If printerImage.Configure() Then Return Me.Enabled = False ' Das Formular wird deaktiviert Application.Busy = 1 ' Das Programm nimmt keine Eingaben mehr entgegen ... printerImage.Print ' Der Druck wird gestartet ... Application.Busy = 0 ' Das Programm nimmt wieder Eingaben entgegen... Me.Enabled = True ' Das Formular wird aktiviert End ' btnPrintImage_Click()
Beispiel 3
Als Teil-Prozess für die Installation eines Programms (Update) aus vorliegenden Paketen wird die Anweisung ./configure -C ausgeführt, die das System analysiert, die Pakete konfiguriert sowie das Makefile generiert. Für die Laufzeit des Teil-Prozesses werden vom Haupt-Programm alle Eingaben ignoriert:
Public Sub btnConfigureUpdate_Click() Inc Application.Busy sShellCommand = "echo 'CONFIGURE';echo '---------------------------';" sShellCommand &= " cd " & sSVNPfad & ";./configure -C" GoToTerminal(GetTerminalList()[0], sShellCommand) btnMakeUpdate.Enabled = True Dec Application.Busy End ' btnConfigureUpdate_Click()
Beispiel 4
Für das Demonstrationsprogramm zur Klasse Watcher (→ Kapitel 20.10 Watcher) sollten die überwachten Ereignisse behandelt und mit Meldungen in eigenen Fenstern dokumentiert werden. Der folgende Quelltext-Ausschnitt aus der Erprobungsphase für das Projekt löste nicht nur Fehler, sondern auch einen Programm-Absturz aus, weil durch das ständige Ändern (Move oder Resize) auch stetig Meldungsfenster erzeugt wurden:
Public Sub wWatcher_Resize() Message.Info(("Das Hauptfenster " & wWatcherObject1.Control.Name & " hat seine Größe verändert!")) Stop Event End ' wWatcher_Resize()
Public Sub wWatcher_Move() Message.Info(("Das Hauptfenster " & wWatcherObject1.Control.Name & " hat seine Position geändert!")) Stop Event End ' wWatcher_Move()
Die Überlegungen und Ansätze zur Lösung:
Hier der korrigierte Quelltext-Ausschnitt:
Private sControlName As String ' ... sControlName = "'" & wWatcherObject1.Control.Name & "'" ' ... Public Sub wWatcher_Resize() Application.Busy = 1 If Application.Busy = 1 Then Message.Info("Das Fenster " & sControlName & " hat die Größe verändert!") Application.Busy = 0 Stop Event End ' wWatcher_Resize() Public Sub wWatcher_Move() Inc Application.Busy If Application.Busy = 1 Then Message.Info("Das Fenster " & sControlName & " hat die Position geändert!") Dec Application.Busy Stop Event End ' wWatcher_Move()