Jump to content

Gambas/FAQ

From Wikibooks, open books for an open world

Back to Gambas

See http://sourceforge.net/mailarchive/forum.php?forum=gambas-user

Hotkeys

[edit | edit source]

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 | edit source]

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.

Listview

[edit | edit source]

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.

Listview.add("Key","Name",NULL,"Key2")

Variables

[edit | edit source]

Does Gambas support structured data types?

[edit | edit source]

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
  bar AS INTEGER
END TYPE
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 Building

[edit | edit source]

Does gambas support include files?

[edit | edit source]

Does gambas support conditional compilation directives?

[edit | edit source]

Application Startup

[edit | edit source]

Making the application startup from a main routine

[edit | edit source]

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:
PUBLIC SUB Main()
  ' This is the start of the program
END
  • Right click the MMain module, then select Startup class from the context menu

Obtaining the command line parameters

[edit | edit source]
PUBLIC SUB main()
  ' 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
  NEXT 
END SUB

Window Geometry

[edit | edit source]

Determining the maximum window size

[edit | edit source]

Overview

[edit | edit source]

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 form

[edit | edit source]

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 _new()
END
PUBLIC SUB Form_Open()
END

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
END