The Qt documentation in C++ of this class can be read here: http://doc.trolltech.com/4.3/qwidget.html
A form itself is a control, which is a window with controls.
Please read the control class overview Control as well.
Important methods:
Important events:
Be sure that you implement some events like OnOpen and OnClose.
Sub Form_OnOpen() ' some inital custom code End Sub Sub Form_OnClose(ByRef Cancel As Boolean) ' some custom code, to close files or other resources, or to check ' if closing of form is currently possible or allowed Cancel = True ' if you would like to abort the closing End Sub ' opening a form Dim f As bernd ' assume that bernd is a form class created with the form designer f = New bernd f.Open() ' OR Forms.Open("bernd") ' for this call you must setup mainwindow in projects properties
Hidden SQL Operating If you need to change sql records without notice for the user, create a form with controls and set the SQLName’s of the controls. Open this form using OpenHidden and use it like you would use a visible form with sql controls and sql bindings
or
use Database, Table and Records.
Escape sequences in SQL statements
Use the following builtin functions
Control, ControlFocus, ControlFirst, ControlNext,
BorderTop, BorderBottom, BorderLeft, BorderRight,
Flag, Modal, Dock, OpenOnRun, StopOnClose
First, Next, Previous, Last, GoTo, Seek, Len, Pos, OnGoTo
Insert, Update, Delete, AddNew, GoTo, Requery, SQLInsert, SQLUpdate, SQLDelete, OnQuery, OnAddNew, OnBeforeInsert, OnBeforeUpdate, OnBeforeDelete
It is possible to set up a form as a login form, which is first shown after the application have been launched and before the mainwindow form appears. It is usally used to ask the user for a user name and password. The login form is set in the project properties dialog in KBasic's IDE.
Function Hwnd() As Long
Implemented since KBasic V1.81.
Returns the native unique window identifier associated with this form. This value is useful for using native API calls for manipulating the form. See the project example “Windows” for more information.
Example
Declare Function BringWindowToTop Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Function ControlAppend (ControlName As String, ControlType As String, ControlGroup As String, X As Integer, Y As Integer, Width As Integer, Height As Integer, Visible As Boolean) As Boolean
Implemented since KBasic V1.75.
See also ControlRemove
Function ControlInsert (ControlName As String, ControlType As String, ControlGroup As String, X As Integer, Y As Integer, Width As Integer, Height As Integer, Visible As Boolean) As Boolean
Implemented since KBasic V1.75.
See also ControlRemove
Function ControlRemove (ControlName As String) As Boolean
Implemented since KBasic V1.75.
See also ControlAppend
Function Control(Name As String) As Control
Returns the control object for a given control name.
Avoid name collision! Use Me.Control(Name As String) if you use this function inside OnKeyDown/OnKeyUp/OnKeyPress(…Control As Boolean…) due to naming of the argument Control As Boolean |
Argument(s)
Name As String | the control, which should be returned |
Return Value | control object |
Example
Dim c As CommandButton c = Control("Button1") ' Button1 is declared as CommandButton in this form Print c.Caption
See also ControlFirst, ControlNext
Function ControlFocus() As Control
Function ControlFocusNext() As Control
Implemented since KBasic V1.75.
Function ControlSetFocusNext() As Boolean
Implemented since KBasic V1.83.
Function ControlSetFocusPrevious() As Boolean
Implemented since KBasic V1.83.
Function ControlFirst() As String
Returns the name of first control of the form. If there is no control, it returns ””.
See also ControlNext
Function ControlNext() As String
Returns the name of next control of the form. If there is no control, it returns ””.
Example
Dim n As String n = ControlFirst() If n <> "" Then Do Dim c As Control c = Control(n) ' place your code here n = ControlNext() Loop While n <> "" End If
See also ControlFirst
Function Load(FormName As String) As Boolean
Loads all controls of the form from the form file and makes them ready. Do NOT call this method explicitly. It is automatically called by KBasic.
Sub OpenPrint()
Prints the report immediately.
Only useable if form is a report.
Sub OpenPrintDialog()
Opens the print dialog for printing.
Only useable if form is a report.
Sub OpenPrintPreview()
Opens a preview for printing the report.
Only useable if form is a report.
Sub MultiPageShow(Page As Integer)
Sub MultiPageShowNext()
Sub MultiPageShowPrevious()
Sub SetWithTag(Tag As String, PropertyName As String, Boolean)
Implemented since KBasic V1.6 (n).
Sub SetWithTag(Tag As String, PropertyName As String, String)
Implemented since KBasic V1.6 (n).
Sub SetWithTag(Tag As String, PropertyName As String, Integer)
Implemented since KBasic V1.6 (n).
Sub SetWithTag(Tag As String, PropertyName As String, Double)
Implemented since KBasic V1.75.
Sub SetWithGroup(Group As String, PropertyName As String, Boolean)
Implemented since KBasic V1.6 (n).
Sub SetWithGroup(Group As String, PropertyName As String, String)
Implemented since KBasic V1.6 (n).
Sub SetWithGroup(Group As String, PropertyName As String, Integer)
Implemented since KBasic V1.6 (n).
Sub SetWithGroup(Group As String, PropertyName As String, Double)
Implemented since KBasic V1.75.
Sub DockSetFloating(Boolean)
Implemented since KBasic V1.75.
Function DockIsFloating() As Boolean
Implemented since KBasic V1.75.
Sub DockTabify(OnFormName As String)
Implemented since KBasic V1.75.
Sub DockSplit(OnFormName As String, Direction As String)
Possible values for Direction are
Implemented since KBasic V1.75.
ReadWrite FormFileName As String
Hidden property.
Implemented since KBasic V1.75
ReadWrite FormModified As Boolean
Hidden property.
Implemented since KBasic V1.75
ReadOnly InnerX As Integer
Implemented since KBasic V1.75
ReadOnly InnerY As Integer
Implemented since KBasic V1.75
ReadOnly OuterWidth As Integer
Implemented since KBasic V1.75
ReadOnly OuterHeight As Integer
Implemented since KBasic V1.75
ReadOnly Resizable As Boolean
If true form’s size may be changed by user.
ReadOnly ResizableBigger As Boolean
If true form’s size may be changed by user. Allows only growing the width and height.
Implemented since KBasic V1.75.
ReadOnly ResizableSmaller As Boolean
If true form’s size may be changed by user. Allows only shrinking the width and height.
Implemented since KBasic V1.75.
ReadOnly TableView As Boolean
If TableView is set to true, a list of all records is shown. After double clicking on one item, the user may change the data of that field. Events of binding controls are not supported in TableView mode, but some properties like InputMask are still provided.
In TableView modes new records may not be appended. The following events are not raised in TableView mode. Updates and new records are done at once.
Relations are not supported in TableView, but the foreign key is displayed.
ReadOnly Dock As String
May only be used, if there is a mainwindow (see properties of project. Additionally, myMenuBar menubar class must be created).
ReadOnly DockCaptionVisible As Boolean
Implemented since KBasic V1.74
ReadOnly DockTabify As String
ReadOnly DockSplit As String
Implemented since KBasic V1.75.
ReadOnly DockWidth As Integer
If set to -1, the dock's width is undefined.
ReadOnly DockHeight As Integer
If set to -1, the dock's height is undefined.
ReadOnly BorderTop As Integer
ReadOnly BorderBottom As Integer
ReadOnly BorderLeft As Integer
ReadOnly BorderRight As Integer
ReadOnly MultiPageHeight As Integer
ReadOnly MultiPageBorderLeft As Integer
ReadOnly MultiPageBorderRight As Integer
ReadOnly MultiPageBorderTop As Integer
ReadOnly MultiPageBorderBottom As Integer
ReadWrite ScrollX As Integer
ReadWrite ScrollY As Integer
ReadWrite ScrollWidth As Integer
ReadWrite ScrollHeight As Integer
ReadWrite ScrollBar As String
ReadWrite MoveOnMouseDrag As Boolean
Implemented since KBasic V1.75.
ReadOnly Flag As String
Implemented since KBasic V1.89®
ReadWrite Icon As String
Sets the icon of the form.
An icon can be an absolute path to an image file (png, jpg,…) like c:\myfolder\myimage.png or can be an relative path to the current project like myimage.png (which is present in the current project directory). Relative paths are recommended.
Might be a String containing binary data. See the binary project example for using.
See also Caption
ReadWrite Caption As String
Sets the window title of the form.
ReadOnly Modal As Boolean
If set to true: Uses the Qt function “setWindowModality(Qt::ApplicationModal);” for the form control. The form is modal to the application and blocks input to all windows.
ReadOnly StopOnClose As Boolean
Stops the application, if the event OnClose returns true.
ReadOnly OpenOnRun As Boolean
Opens automatically this form on application start up.
Only useable if control is a form control.
Function EventSource() As Control
Implemented since KBasic V1.75.
ShowFullScreen → OnShow, ShowMaximized → OnShow, ShowMinimized → OnShow, ShowNormal → OnShow,
Function First() As Boolean
Function Next() As Boolean
Function Previous() As Boolean
Function Last() As Boolean
Function GoTo(Position As Integer) As Boolean
Function Insert() As Boolean
Not available in TableView mode.
Function Update() As Boolean
Not available in TableView mode.
Function Delete() As Boolean
Function AddNew() As Boolean
Not available in TableView mode.
Function Length() As Integer
Function Position() As Integer
Function IsDirty() As Boolean
Not available in TableView mode.
Function Run(SQLStatement As String) As Boolean
Function Get(SearchFor As String, InTableDotField As String, ReturnFieldName As String) As AnyType
Example
Dim r As String = Get("99", "mytable.id", "name")
If the field is of sql database table type 'Text' you must always not forget to setup the the SearchFor correctly. e.g. 'mytext', 'bernd', without ' it will fail.
If InTableDotField is “*”, the last found record with this function is used to provide the return type.
Function Get(SQLStatement As String) As AnyType
Example
Dim r As Integer = Get("SELECT kbrecordid, name FROM address WHERE name='Bernd' ORDER BY name")
Function PrimaryKey() As Integer
Implemented since KBasic V1.79.
Returns the value of the primary key of the current record. Before V1.89, it returns the value of “kbrecordid” always.
Function PrimaryKeyName() As String
Implemented since KBasic V1.79.
Returns the name of the primary key of the current record. Before V1.89, it returns “kbrecordid” always.
Function kbrecordid() As Integer
Returns the kbrecordid of the current record.
Function kbrecordid(FormView As String) As Integer
Returns the kbrecordid of the current record of a form contained in a form view.
If FormView = ”” the only form as form view. Of course, if so there must be one form view only.
Function Seek(Filter As String = ””, [Filter As String = ””]) As Boolean
Upto six filters are allowed. Move the current position until the record with matching entries could be found.
Example
Seek() ' select the control you wish to seek for, before Seek("id = 12", "name <> 'test'", "age > 12")
Warning
This function might be slow on recordsets with many thousands entries.
Sub Requery()
Sub ClearFilter()
Implemented since KBasic V1.79.
Function IsFilterActive() As Boolean
Sub AddFilter(String = ””)
Unlike SetFilter AddFilter does NOT removes the previous custom filter set by the user. Removing previous filter set, must be done by using ClearFilter.
If you you do not provide an argument, the filter will take effect on the last visited control with the operator ”=”.
Possible operators:
AddFilter() ' filters for the last visited control by the user with operator "=" AddFilter("=") ' filters for the last visited control by the user AddFilter("<>") ' filters for the last visited control by the user AddFilter("name = 'Bernd'")
Sub SetFilter(String = ””)
Unlike AddFilter SetFilter removes the previous custom filter set by the user.
If you you do not provide an argument, the filter will take effekt on the last visited control with the operator ”=”.
Possible operators:
SetFilter() ' filters for the last visited control by the user with operator "=" SetFilter("=") ' filters for the last visited control by the user SetFilter("<>") ' filters for the last visited control by the user SetFilter("name = 'Bernd'")
Sub SortAscending(String = ””)
SortAscending("name")
Sub SortDescending(String = ””)
SortDesc("name")
ReadWrite SQLName As String
Just write the table name you would like to use. If TableView = True, only select the database fields you would like to display.
ReadOnly SQLRelation As String
Useful for child controls as forms and m:n relations or 1:n relations.
ReadOnly SQLControls As String
If set empty, it will shows all SQL controls (default), otherwise only determined controls are visible at runtime.
If set 'False', it is not possible for the user to add new records to the database in this form. The 'Add New' button is not visible at all.
ReadWrite SQLAddNew As Boolean
If set 'False', it is not possible for the user to change existing records to the database in this form.
ReadWrite SQLUpdate As Boolean
If set 'False', it is not possible for the user to delete existing records in the database in this form. The 'Delete' button is not visible at all.
ReadWrite SQLDelete As Boolean
First → OnGoTo, Next → OnGoTo, Previous → OnGoTo, Last → OnGoTo, GoTo → OnGoTo, Seek → OnGoTo
Insert → OnBeforeInsert, Update → OnBeforeUpdate, Delete → OnBeforeDelete, AddNew → OnAddNew, GoTo → OnGoTo
Query first time loaded → OnQuery, Requery → OnQuery
Record data changed by user → OnDirty
AddNew (Button) clicked/raised → OnAddNew → OnDirty
Delete (Button) clicked/raised → OnBeforeDelete
Insert (Button) clicked/raised → OnBeforeInsert
Update (Button) clicked/raised → OnBeforeUpdate
Position changed → OnGoTo
OnScroll()
This event is raised whenever the values of scrollbars of a form have been changed.
OnGoTo()
This event is raised after the current record position changed.
OnQuery()
This event is raised, before the SQL query of the form is executed. Maybe launched by setting a filter or sorting, by clicking on the 'Refresh' button…
OnAddNew()
This event is raised, after the user clicked on the 'Add New' button.
Not available in TableView mode.
OnDirty()
This event is raised, after the user changed some value(s) in the current control binding to the current record. The changed values of the controls need to be updated in the record of the database table by clicking on the 'Update' button, because so the current record is marked as dirty and the user is asked to save those changes into database, when trying to move to another record.
Not available in TableView mode.
OnBeforeInsert(ByRef Cancel As Boolean)
Not available in TableView mode.
OnBeforeUpdate(ByRef Cancel As Boolean)
Not available in TableView mode.
OnBeforeDelete(ByRef Cancel As Boolean)
OnDockMove()
Implemented since KBasic V1.75.
OnDockShow()
Implemented since KBasic V1.75.
OnDockHide()
Implemented since KBasic V1.75.
OnDockFloating()
Implemented since KBasic V1.75.
OnDockNotFloating()
Implemented since KBasic V1.75.
Dim f As bernd ' assume that bernd is a form class created with the form designer f = New bernd f.Open()
Written by Bernd Noetscher
Date 2007-02-22