User Tools

Site Tools


form

Form (QWidget)

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

  • Function Encode(String) As String
  • Function Decode(String) As String

OVERVIEW

LOGIN

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.

METHODS

Hwnd

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

ControlAppend

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


ControlInsert

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


ControlRemove

Function ControlRemove (ControlName As String) As Boolean

Implemented since KBasic V1.75.

See also ControlAppend


Control

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 Valuecontrol object

Example

Dim c As CommandButton
c = Control("Button1") ' Button1 is declared as CommandButton in this form
Print c.Caption

See also ControlFirst, ControlNext


ControlFocus

Function ControlFocus() As Control


ControlFocusNext

Function ControlFocusNext() As Control

Implemented since KBasic V1.75.


ControlSetFocusNext

Function ControlSetFocusNext() As Boolean

Implemented since KBasic V1.83.


ControlSetFocusPrevious

Function ControlSetFocusPrevious() As Boolean

Implemented since KBasic V1.83.


ControlFirst

Function ControlFirst() As String

Returns the name of first control of the form. If there is no control, it returns ””.

See also ControlNext


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


Load

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.


OpenPrint

Sub OpenPrint()

Prints the report immediately.

Only useable if form is a report.


OpenPrintDialog

Sub OpenPrintDialog()

Opens the print dialog for printing.

Only useable if form is a report.


OpenPrintPreview

Sub OpenPrintPreview()

Opens a preview for printing the report.

Only useable if form is a report.


MultiPageShow

Sub MultiPageShow(Page As Integer)


MultiPageShowNext

Sub MultiPageShowNext()


MultiPageShowPrevious

Sub MultiPageShowPrevious()


SetWithTag

Sub SetWithTag(Tag As String, PropertyName As String, Boolean)

Implemented since KBasic V1.6 (n).


SetWithTag

Sub SetWithTag(Tag As String, PropertyName As String, String)

Implemented since KBasic V1.6 (n).


SetWithTag

Sub SetWithTag(Tag As String, PropertyName As String, Integer)

Implemented since KBasic V1.6 (n).


SetWithTag

Sub SetWithTag(Tag As String, PropertyName As String, Double)

Implemented since KBasic V1.75.


SetWithGroup

Sub SetWithGroup(Group As String, PropertyName As String, Boolean)

Implemented since KBasic V1.6 (n).


SetWithGroup

Sub SetWithGroup(Group As String, PropertyName As String, String)

Implemented since KBasic V1.6 (n).


SetWithGroup

Sub SetWithGroup(Group As String, PropertyName As String, Integer)

Implemented since KBasic V1.6 (n).


SetWithGroup

Sub SetWithGroup(Group As String, PropertyName As String, Double)

Implemented since KBasic V1.75.


DockSetFloating

Sub DockSetFloating(Boolean)

Implemented since KBasic V1.75.


DockIsFloating

Function DockIsFloating() As Boolean

Implemented since KBasic V1.75.


DockTabify

Sub DockTabify(OnFormName As String)

Implemented since KBasic V1.75.


DockSplit

Sub DockSplit(OnFormName As String, Direction As String)

Possible values for Direction are

  • Horizontal
  • Vertical

Implemented since KBasic V1.75.


PROPERTIES

FormFileName

ReadWrite FormFileName As String

Hidden property.

Implemented since KBasic V1.75


FormModified

ReadWrite FormModified As Boolean

Hidden property.

Implemented since KBasic V1.75


InnerX

ReadOnly InnerX As Integer

Implemented since KBasic V1.75


InnerY

ReadOnly InnerY As Integer

Implemented since KBasic V1.75


OuterWidth

ReadOnly OuterWidth As Integer

Implemented since KBasic V1.75


OuterHeight

ReadOnly OuterHeight As Integer

Implemented since KBasic V1.75


Resizable

ReadOnly Resizable As Boolean

If true form’s size may be changed by user.


ResizableBigger

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.


ResizableSmaller

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.


TableView

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.

  • OnAddNew
  • OnDirty
  • OnBeforeInsert
  • OnBeforeUpdate

Relations are not supported in TableView, but the foreign key is displayed.


Dock

ReadOnly Dock As String

May only be used, if there is a mainwindow (see properties of project. Additionally, myMenuBar menubar class must be created).


DockCaptionVisible

ReadOnly DockCaptionVisible As Boolean

Implemented since KBasic V1.74


DockTabify

ReadOnly DockTabify As String


DockSplit

ReadOnly DockSplit As String

Implemented since KBasic V1.75.


DockWidth

ReadOnly DockWidth As Integer

If set to -1, the dock's width is undefined.


DockHeight

ReadOnly DockHeight As Integer

If set to -1, the dock's height is undefined.


BorderTop

ReadOnly BorderTop As Integer


BorderBottom

ReadOnly BorderBottom As Integer


BorderLeft

ReadOnly BorderLeft As Integer


BorderRight

ReadOnly BorderRight As Integer


MultiPageHeight

ReadOnly MultiPageHeight As Integer


MultiPageBorderLeft

ReadOnly MultiPageBorderLeft As Integer


MultiPageBorderRight

ReadOnly MultiPageBorderRight As Integer


MultiPageBorderTop

ReadOnly MultiPageBorderTop As Integer


MultiPageBorderBottom

ReadOnly MultiPageBorderBottom As Integer


ScrollX

ReadWrite ScrollX As Integer


ScrollY

ReadWrite ScrollY As Integer


ScrollWidth

ReadWrite ScrollWidth As Integer


ScrollHeight

ReadWrite ScrollHeight As Integer


ScrollBar

ReadWrite ScrollBar As String


MoveOnMouseDrag

ReadWrite MoveOnMouseDrag As Boolean

Implemented since KBasic V1.75.


Flag

ReadOnly Flag As String

  • For a tool window set: Tool + SystemMenu
  • For a dialog window set: Dialog + SystemMenu

Implemented since KBasic V1.89®

  • For a normal form in a MDI/SDI application set: Stand-alone Form when MDI/SDI

Icon

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


Caption

ReadWrite Caption As String

Sets the window title of the form.


Text

Property Text As String (ReadWrite)

Same as Caption. Provided for easy-use.


Value

Property Value As String (ReadWrite)

Same as Caption. Provided for easy-use.


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.


StopOnClose

ReadOnly StopOnClose As Boolean

Stops the application, if the event OnClose returns true.


OpenOnRun

ReadOnly OpenOnRun As Boolean

Opens automatically this form on application start up.

Only useable if control is a form control.


EventSource

Function EventSource() As Control

Implemented since KBasic V1.75.


EVENTS

SQL METHODS

First

Function First() As Boolean


Next

Function Next() As Boolean


Previous

Function Previous() As Boolean


Last

Function Last() As Boolean


GoTo

Function GoTo(Position As Integer) As Boolean


Insert

Function Insert() As Boolean

Not available in TableView mode.


Update

Function Update() As Boolean

Not available in TableView mode.


Delete

Function Delete() As Boolean


AddNew

Function AddNew() As Boolean

Not available in TableView mode.


Length

Function Length() As Integer


Position

Function Position() As Integer


IsDirty

Function IsDirty() As Boolean

Not available in TableView mode.


Run

Function Run(SQLStatement As String) As Boolean


Get

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.


Get

Function Get(SQLStatement As String) As AnyType

Example

Dim r As Integer = Get("SELECT kbrecordid, name FROM address WHERE name='Bernd' ORDER BY name")

PrimaryKey

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.


PrimaryKeyName

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.


kbrecordid

Function kbrecordid() As Integer

Returns the kbrecordid of the current record.


kbrecordid

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.


Seek

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.


Requery

Sub Requery()


ClearFilter

Sub ClearFilter()


IsFilterActive

Implemented since KBasic V1.79.

Function IsFilterActive() As Boolean


AddFilter

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'")

SetFilter

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'")

SortAscending

Sub SortAscending(String = ””)

SortAscending("name")

SortDescending

Sub SortDescending(String = ””)

SortDesc("name")

SQL PROPERTIES

SQLName

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.


SQLRelation

ReadOnly SQLRelation As String

Useful for child controls as forms and m:n relations or 1:n relations.


SQLControls

ReadOnly SQLControls As String

If set empty, it will shows all SQL controls (default), otherwise only determined controls are visible at runtime.


SQLAddNew

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


SQLUpdate

If set 'False', it is not possible for the user to change existing records to the database in this form.

ReadWrite SQLUpdate As Boolean


SQLDelete

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


SQL EVENTS

FirstOnGoTo, NextOnGoTo, PreviousOnGoTo, LastOnGoTo, GoToOnGoTo, SeekOnGoTo

InsertOnBeforeInsert, UpdateOnBeforeUpdate, DeleteOnBeforeDelete, AddNewOnAddNew, GoToOnGoTo

Query first time loaded → OnQuery, RequeryOnQuery

Record data changed by user → OnDirty

AddNew (Button) clicked/raised → OnAddNewOnDirty

Delete (Button) clicked/raised → OnBeforeDelete

Insert (Button) clicked/raised → OnBeforeInsert

Update (Button) clicked/raised → OnBeforeUpdate

Position changed → OnGoTo

OnScroll

OnScroll()

This event is raised whenever the values of scrollbars of a form have been changed.


OnGoTo

OnGoTo()

This event is raised after the current record position changed.


OnQuery

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

OnAddNew()

This event is raised, after the user clicked on the 'Add New' button.

Not available in TableView mode.


OnDirty

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

OnBeforeInsert(ByRef Cancel As Boolean)

Not available in TableView mode.


OnBeforeUpdate

OnBeforeUpdate(ByRef Cancel As Boolean)

Not available in TableView mode.


OnBeforeDelete

OnBeforeDelete(ByRef Cancel As Boolean)


OnDockMove

OnDockMove()

Implemented since KBasic V1.75.


OnDockShow

OnDockShow()

Implemented since KBasic V1.75.


OnDockHide

OnDockHide()

Implemented since KBasic V1.75.


OnDockFloating

OnDockFloating()

Implemented since KBasic V1.75.


OnDockNotFloating

OnDockNotFloating()

Implemented since KBasic V1.75.


COMMENTS

Open a form

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

form.txt · Last modified: 2013/04/09 22:57 (external edit)