In the first example, a dialogue is developed that is called up before the main program and is used to enter two pieces of data - a freely selectable name and a password. When planning your own dialogue, questions to be answered include the following, although the order does not imply any ranking:
In relation to the 1st project, here are the answers:
With these preliminaries, the development of a custom dialogue can be tackled.
In essence, one defines a dialogue box → Figure 188.8.131.52.1 and calls it using the special _call(..)-method in the main program. For information on this method, see the Gambas documentation → http://gambaswiki.org/wiki/lang/special/call. In the optional arguments of the _call(…) method you can pass data to the dialogue and read data from the dialogue in the return value of the method (function value). By calling the _call(..) method, the dialogue box can display itself modally! Now you can edit the data in the dialogue. If the dialogue box is closed, the ShowModal() call - this happened automatically - returns to the _call() call and you can read data from the dialogue.
This all takes place in the Open event of the main form in the first example - before this form is displayed! The _call() method allows you to use an object syntactically like a function. Use the _call(..) method whenever a form (or a class in general) has a very specific task that it can do itself, without needing event handlers in other classes, for example.
The following two source texts for example 1 show the implementation of an own dialogue in Gambas:
Source code (main) program (FMain.class):
 ' Gambas class file   Public Sub Form_Open()  Dim cData As Collection  Dim sDialogTitel As String  Dim frmLogin As New FLogin   FMain.Center  FMain.Resizable = False  sDialogTitel = "Enter the data!"   ' Before the main window is displayed, the login window is automatically opened 'modally'.  cData = frmLogin(sDialogTitel)  If Not cData Then ' Cancel?  Me.Close() ' Exit the main program without a comment.  Return  Endif   If cData["password"] <> "mgA+" Then ' Failed login attempt? End with comment.  Message.Title = "Error in the dialogue box".  Message.Error("Login failed!")  Me.Close()  Return  Else  ' Otherwise start main program ...  lblGreet.Text = Subst$("So you are &1. Good to know!", cData["name"])  Endif   End ' Form_Open()
Source code dialogue (FLogin.class):
 ' Gambas class file   Public Sub _call(sTitel As String) As Collection  Me.Text = sTitel   If Me.ShowModal() = 0 Then  Return Null  Else  Return ["name": txtName.Text, "password": txtPassword.Text]  Endif   End ' _call(sTitel As String)   Public Sub btnCancel_Click()  Me.Close(0)  End ' btnCancel_Click()   Public Sub btnOK_Click()  Me.Close(1)  End ' btnOK_Click()   Public Sub txtName_Activate()  txtPassword.SetFocus()  End ' txtName_Activate()   Public Sub txtPassword_Activate()  btnOK_Click()  End ' txtPassword_Activate()
The results in the first example are not spectacular - but exactly those that were to be expected.The dialogue is displayed as a preliminary program and you are prompted to enter the required data:
If the password is incorrect - stored in the return value of the dialogue cData[“password”] - you will see this message and then nothing more … .
If the login was successful, the main program is displayed. The name entered in the dialogue (cData[“name”]) is used in the comment: