Back to Gambas



If you want to use some hotkeys for a project, you might code something like this:

Public sub Form_KeyPress ()
 If key.code = ... then
 Something happens

Unfortunately this only works, if the form has no buttons and other controls. If the form has other controls and one of the controls has the focus, then it does not work.

There is no interface in the QT component to globally intercept key events yet, but there is a trick:

If you have a menu in your form, its keyboard shortcuts are globally managed. So you can add an hidden menu to your form to solve your problem.

KDE panel applet ?Edit

Is it possible to write a KDE panel applet with Gambas?

No, currently it is not possible to do that. KDE panel applets are implemented as shared libraries with specific interfaces.


How can I add a listview item after an existing one, when there is an item missing:

Wrong: Listview.add("Key","Name",,"Key2") -- Error: Comma missing.

You have to pass NULL as picture argument. You cannot "jump" arguments when you call a function in Gambas.



Does Gambas support structured data types?Edit

In some versions of basic, it is possible to create structured data types using by using type definitions as follows:

' This will not work in Gambas
TYPE rhubarbstructure
  foo AS STRING * 32
PUBLIC rhubarb AS rhubarbstructure

Currently, Gambas does not support the TYPE keyword. Instead, you can use the STRUCT or STRUCT[] keywords.

Additionally, it is possible to use class definitions for the same effect.

Project BuildingEdit

Does gambas support include files?Edit

Does gambas support conditional compilation directives?Edit

Application StartupEdit

Making the application startup from a main routineEdit

In gambas, to make an application startup from a main routine:

  • Create a new module called MMain
  • In the MMain module, create a public sub called Main as follows:
  ' This is the start of the program
  • Right click the MMain module, then select Startup class from the context menu

Obtaining the command line parametersEdit

  ' This reads and displays the command line parameters
  DIM l AS Integer
  DIM numparms AS Integer
  DIM parm AS String
  numparms = Application.Args.Count
  FOR l = 0 TO numparms - 1
    parm = Application.Args[l]
    PRINT l; " : "; parm

Window GeometryEdit

Determining the maximum window sizeEdit


In gambas, the trick to determining the maximum window size that will fit on the screen is to create a form that is maximized and then query its dimensions from within a Form_Resize() event. Note that the form can be invisible during this process, and typically we would use the main modal window (FMain in this example).

Creating the formEdit

From with the project create a form (FMain) with the following properties set:

FMain.Maximized = True
FMain.Visible = False    ' The form can be invisible

From within the project view, rightclick the FMain form and select Edit class from the contextmenu. This will display a form class file (FMain.class) as follows:

PUBLIC SUB Form_Open()

We can now add a Form_Resize() event to the class file with the necessary code to obtain the screen dimensions as follows:

PUBLIC SUB Form_Resize()
  PRINT "The maximum window size that can be used is "; FMain.Width; " x "; FMain.Height