VCLua v0.3.2

Creating VCLua application step by step

Tutorial 1

Form, Menu and ToolBar



Before you start writing your application, be shure that VCLua library is loaded.

require "VCL"

First you should create the main form of the application

mainForm = VCL.Form("mainForm")

The properties of the form can be assigned as single property or as array of properties (lua table)

-- [property names are case-insensitive]
mainForm.Caption = "My first VCLua application"
mainForm._= { position="podesktopcenter", height=400, width=600, image="/usr/tmp/MyApp.Ico"}

To capture an event of the form you should set the proper eventname property. The property value is the name of the global lua function which handles the event.

mainForm.onclosequery = "onCloseQueryEventHandler"

function onCloseQueryEventHandler(Sender)
    return true -- the form can be closed

If you want use menus, first create the menu and load the menuitems from a lua table

mainMenu = VCL.MainMenu(mainForm,"mainMenu")
    {name="mmfile", caption="&File",
            {name="mmOpen", caption="Open...", onclick="onMenuOpenClick", shortcut="Ctrl+O"},
            {caption="Exit", onclick="onMenuExitClick", shortcut="Alt+F4"},
    {name="mmhelp", caption="&Help", RightJustify=true,
        submenu = {
            {caption="Help", shortcut="F1"},

To access menuitems at runtime use the find method. Only the manually named items can be found trough this method!

mainMenu:Find("mmhelp"):Add("mmAbout")._= {caption="About", onclick="onMenuAboutClick", enabled=false}

Dont forget handle all the living events!

function onMenuExitClick()

Using of the Toolbar component improves and beautifies your application. (Without images the toolbar looks very weird)

mainToolbar = VCL.ToolBar(mainForm,"mainToolbar")
    {name="mtbOpen", onclick="onMenuOpenClick"},
    {name="mtbExit", onclick="onMenuExitClick"},

Finally start your VCLua application


Destroy form after modal run ends