The Wizard class is mainly used to realise a dialogue that consists of several steps, which can be cancelled if necessary, and which triggers a certain action in the final step with the OK button, which provides dialogue data. On the other hand, the Wizard component can also be used to navigate through a sequence of steps - without returning a result, as would be the case with a help wizard, for example.
In the development of the projects presented - in which the two use cases mentioned above are realised - the preliminary considerations referred to in the first part of chapter → 12.6.1 'TabStrip - Projects' have proven to be adequate.
The first project is characterised by using a wizard for a dialogue. The dialogue is called by a database programme and provides it with an active DB connection as a result of a successful dialogue, or no DB connection if the dialogue was aborted or faulty.
Figure 188.8.131.52: Calling a dialogue (wizard) in the database programme
Source code extract from the database programme:
Private $hConnection As Connection Public Sub Form_Open() FMain.Center End ' Form_Open() Public Sub mnuOpen_Click() Dim hNewConnection As Connection Try $hConnection.Close() hNewConnection = FMakeConnection.RunDialog() If Not hNewConnection Then Return $hConnection = hNewConnection Refresh() End ' mnuOpen_Click()
In the class FMakeConnection.class, the RunDialog() function contains the complete dialogue.
Source text dialogue:
 ' Gambas class file   Private $hDBConnection As New Connection  Private Const ACTIONTEXT As String = "Open database"   Public Function RunDialog() As Connection  Me.ShowModal()  Return $hDBConnection  End ' Run() As Connection   Public Sub Form_Open()   FMakeConnection.Text = "Dialog - Database connection"   wizConnect.Count = 3  wizConnect.Animated = True  wizConnect.Margin = True  wizConnect.ShowTitle = True  wizConnect.ShowButton = True   wizConnect.ActionPicture = Picture["icon:/16/view-detail"]  wizConnect.ActionText = ACTIONTEXT   wizConnect.ShowIndex = True  wizConnect.Text = "Select the database type!" ' #1  wizConnect.Text = "Select a SQLite3 database!" ' #2  wizConnect.Text = "Enter credentials and connect to the server with '" & ACTIONTEXT & "'.!"  ' Start-Verzeichnis im FileChooser (Step #2 - SQLite3)  fchSqlite.Root = Application.Path &/ "DBSQLite3"   End ' Form_Open()   Public Sub wizConnect_BeforeChange()  ' If SQLite3 is selected as the DBMS, then show step #2.  ' and hide step #3. Opposite for MySQL and PostgreSQL.   If Not wizConnect[wizConnect.Index].Enabled Then Return  If radSqlite3.Value = True Then  wizConnect.Enabled = True ' Step #2 display  wizConnect.Enabled = False ' Step #3 hide  wizConnect.ActionText = "Open SQLite3-database"  Else  wizConnect.Enabled = True ' Step #3 display - logically this is step 2  wizConnect.Enabled = False ' Step #2 hide  ' Set port for PostgreSQL (5432) or MySQL (3306) in step #3  spbPort.Value = IIf(radPostgreSql.Value, 5432, 3306)  wizConnect.ActionText = ACTIONTEXT  Endif  End ' wizConnect_BeforeChange()   Public Sub wizConnect_Close()   If radSqlite3.Value Then  If Not fchSqlite.SelectedPath Then  Message.Error("No database file was selected.")  Return  Endif  $hDBConnection.Type = "sqlite3"  $hDBConnection.Name = fchSqlite.SelectedPath  Else  $hDBConnection.Type = IIf(radPostgreSql.Value, "postgresql", "mysql")  $hDBConnection.Host = txtHost.Text  $hDBConnection.Port = spbPort.Value  $hDBConnection.Login = txtUser.Text  $hDBConnection.Password = txtPassword.Text  $hDBConnection.Name = txtDatabase.Text  Endif  $hDBConnection.Open()  Me.Close()  Catch  Message.Error(Error.Text)  End ' wizConnect_Close()   Public Sub wizConnect_Cancel()  Me.Close()  End ' wizConnect_Cancel()   Public Sub wizConnect_Change()  ' Print "CURRENT INDEX = "; wizConnect.Index  End ' wizConnect_Change()   Public Sub Form_Close()  If Not $hDBConnection Or If Not $hDBConnection.Opened Then $hDBConnection = Zero  End ' Form_Close()
Figure 184.108.40.206.2: Display of the DB data for the table 'contacts' in the selected database.
Figure 220.127.116.11.3: Step 1 - DBMS selection
In the first step of the wizard, a database management system (DBMS) can be selected.
Figure 18.104.22.168.4: Step 2 - Selection SQLite3 database
In the 2nd step, for example, an SQLite3 database is selected.
Notice: In project 1, an SQLite3 database is provided in the project folder for you to try out yourself. You can restart the dialogue at any time via the DB programme menu.
The second project uses a wizard to navigate through several related steps. The display of a recipe in 4 steps serves as an example. Since no action needs to be triggered in the last step and the display can be cancelled at any time by the end of the programme, the buttons are not displayed in the lower panel of the wizard. Therefore, set the property Wizard.ShowButton to False already in the IDE.
However, you now have to take care of the navigation between the individual steps yourself. This can be done without problems by using the two methods Wizard.MoveNext and Wizard.MovePrevious:
Public Sub btnNext_Click() If wizRezept.Index < wizRezept.Count Then wizRezept.MoveNext btnPrevious.Enabled = True Endif If wizRezept.Index = wizRezept.Count - 1 Then btnNext.Enabled = False End ' btnNext_Click()
Public Sub btnPrevious_Click() If wizRezept.Index < wizRezept.Count Then wizRezept.MovePrevious btnNext.Enabled = True Endif If wizRezept.Index = 0 Then btnPrevious.Enabled = False End ' btnPrevious_Click()
In the following figure you can see the content of the 2nd step and the two buttons for navigation as well as the end button:
For project 3 - which is similar in layout to the first project - only the project archive is made available to you for testing. The project implements the installation of Gambas in the current version via SVN. The wizard has only 2 steps:
First check whether the Subversion programme is installed on the system. If it is not, the programme will exit with an error message.Otherwise, the very first time you start the programme, the first step 1K will be displayed and you can specify the installation path or choose the default path.At each subsequent start of the programme, step 1U will be displayed and an update will be offered if the version on the server is higher than the version of the local copy of the SVN repository. The directory for the local SVN repository is saved at the end of the programme and read in at the start of the programme (Settings class).
Figure 22.214.171.124.1: Display step 1K
Figure 126.96.36.199.2: Local copy of the SVN repository.
Figure 188.8.131.52.3: Display step 1U
Figure 184.108.40.206.4: Update of the local SVN repository
Figure 220.127.116.11.5: Step 2 - Installing Gambas
In step 2 of the wizard you can still specify the number of jobs and then start the installation of Gambas.
If this interface is displayed when starting the programme, you can either force a reconfiguration of the sources or cancel the programme or install the displayed local version of Gambas after 'Next' - if this has not already been done: