VCLua v0.3.2

Creating VCLua application step by step

Tutorial 1

Form, Menu and ToolBar

 tut01.lua

 

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
end

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

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

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()
    mainForm:Close()
end

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

mainToolbar = VCL.ToolBar(mainForm,"mainToolbar")
mainToolbar:LoadFromTable({
    {name="mtbOpen", onclick="onMenuOpenClick"},
    {name="mtbExit", onclick="onMenuExitClick"},
})
mainToolbar:Find("mtbOpen").enabled=false

Finally start your VCLua application

mainForm:ShowModal()

Destroy form after modal run ends

mainForm:Free()