
//Display message box prompting user to confirm.
IF Form.MessageBox("Close", "Close this form?", MB_OKCANCEL) == IDOK
{
Form.Close()
}
Note:
Form.MessageBox("Close", "Close this form?", MB_OKCANCEL) – this method will return either the system constants IDOK or IDCANCEL, depending on which button the user clicks. The buttons that available to the user are determined by the last argument of the Form.MessageBox method.
//Reset buffers.
Form.ResetChildData()
//Set query parameter for child.
Form.SetChildFormQueryParameter("pProductID", edProID)
//Set child variable.
Form.SetChildFormVariable("strProductName", edProName)
Form.OpenChildForm("Child")
Note:
Form.ResetChildData() should be run before setting any child form data.
edProID and edProName are edit controls.
//Open the filename browser dialog window.
strFilename = Form.ShowFileOpenDialog()
//If no file was selected, the method will return an empty string.
IF strFilename <> ""
{
edTextField = File.LoadText(strFilename)
}
Note:
Form.ShowFileOpenDialog()will open a browse filename window and return the filename as a string.
strFilename – a Form Variable, string.
edTextField – a Form Control, edit control.
//Disable all sync rules.
Synchroniser.DisableAll()
//Enable
Synchroniser.EnableSyncRule("SyncAll", true)
//Perform synchronisation
Form.ShowSyncDialog(false)
Note:
Form.ShowSyncDialog – This method performs the synchronisation.
IF edtPassword <> edtConfirmPasswrd
{
Form.MessageBox("Password", "Password entries are not the same.", MB_ICONEXCLAMATION)
}
ELSE
{
Settings.SettingPassword = edtPassword
Form.MessageBox("Password", "Password successfully changed. ", MB_ICONEXCLAMATION)
edtPassword = ""
edtConfirmPasswrd = ""
Form.ShowTab(0)
}
Note:
This expression is part of the following form. It is linked to the Change button.
On successful password change, the command returns to the Synchronise tab.
edtPassword and edtConfirmPasswrd are form controls that accepts the user password.
Settings.SettingPassword – an application setting (AppSetting) that contains the password and is stored into a file .bsa file.
IF blnFormNew
{
Form.New()
}
Note:
blnFormNew – a flag to check if the form should prepare itself for record creation or not.
This expression is linked to an Action-Open property of the cursor form. You can open the cursor form with an Add New button on the parent form that initialises blnFormNew to true. Or you can also use the same cursor form to open existing records by simply initialising the flag to false.
IF Form.SaveRecord() <> 0
{
Form.MessageBox("Save", "Could not save customer details", MB_OK)
Form.CancelOpen = true
}
Note:
This expression is linked to a Pre-Open Expression of the OpenForm action of the Orders button. The Orders button will open the OrderForm to add order records for the new customer. The customer records will automatically be saved before opening the OrderForm. But if the save was not successful, opening the child form will be cancelled.
Form.CancelOpen – the flag that cancels the opening of the child form. This can be found under “Data Sources/Form/Properties”
The SaveRecord method can only be used with forms binded to a query.
IF Form.IsLastRecord()
{
Form.Close()
}
ELSE
{
Form.MoveNext()
}
Note:
Instead of using the navigation bars of the cursor form, you can add a Next button on the form and attached this expression to its Action-Click property.
This expression will act like the next button of the navigation bars. If it’s the last record the form will be closed but if its not, it will move to the next record using the Form.MoveNext method.
You can also create a Previous button and use the IsFirstRecord and MovePrevious methods respectively.
IF Child.Result == 1
{
IsAdmin = Form.GetChildFormVariable("IsAdmin")
btnLogin = "Logout"
IF IsAdmin
{
btnAdmin.Show()
}
btnCustomer.Show()
btnCustomer.SetFocus()
}
Note:
This expression checks if login was successful. It is linked to a Post-Close Expression of the OpenForm action of the Login button. The LoginForm returns a result of 1 if login was successful and also initialises the form variable IsAdmin.
GetChildFormVariable – as the name implies obtains the value last stored to the form variable IsAdmin. Based from the return value of this method, the program will show and hide form controls.
Pre-open expression
Form.SaveRecord()
Form.SetJumpColumn("BRAND", edtJumpBrand)
Form.SetJumpColumn("PACK", edtJumpPack)
Post-close expression
Form.Refresh()
Form.Jump()
Note:
The Jump method is useful to go back to the current record position you were editing before opening a child form and refreshing the cursor form on post-opening of the child form.
When a cursor form saves a new record, this record is appended at the end of the record list but it does not order the records yet based on the query as the query was not run. On a refresh, the query will be run and the records will be re-ordered. When you refresh the cursor form after opening the child form, if you do not use the Jump method, the record position will be at the end of the list and this might not be the record you were editing.
Pre-open expression – this expression will be executed before opening the child form. Link this expression to the Pre-Open Expression of the Form-Open dialog of any Action event property of a form control. As can be seen from the expression, you should save the record first and initialise the SetJumpColumn values before opening the child form.
Post-close expression – this expression will be executed after the child form was opened. This refreshes the cursor form and jumps to the record specified by the SetJumpColumn values.
Important Note : Submenu items can only enabled or disabled using the EnableMenuItemByIndex method. Further note that the EnableMenuItemByPosition method can only be used to enable/disable non-submenu items.
The below examples are based on two form menus :
Menu1 – User menu id = 0
Item1 à index = 0, position = 0
Item2 à index = 1, position = 1
Item3 à index = 2, position = 2
Menu2 – User menu id = 1
Menu2 Item à index = 3, position = 0
SubMenu à index = N/A, position =1
Sub1 à index = 4, position = N/A
Sub2 à index = 5, position = N/A
Menu2 Item3 à index = 6, position = 2 (i.e. SubMenu position =1)
The following sample code will disable Menu2 Item3 and Sub1 menu items using the menu indexes..
Note that SubMenu in Menu2 does not have an index as it is not actionable menu item.
Form.EnableMenuItemByIndex(1, 4, false)
Form.EnableMenuItemByIndex(1, 6, false)
Form.EnableMenuItemByIndex(0, 0, false)
Form.EnableMenuItemByIndex(0, 2, false)