Menu

XMLReader example in VCLua 0.5.x

Lazarus has some interesting examples, one of this is the XMLReader.
But who wants waste time to make gui forms with script language? Much easier to make it with a standard formdesigner and just load it on runtime...

  1. Use "Save Form as XML" option in Lazarus Ide on a form.
  2. Check the XML, remove any 'binary' tags. ( yes, this is a bug in lazarus ide )
  3. finally write your lua script in 5 mins. or less ...
    (This sample works in current development {v0.5})
require "vcl"
VCL = vcl

-- XMLFormToLua loads the exported XML form and converts it to lus script.
loadstring(VCL.XMLFormToLua("testform.xml"))()

-- We will need the Load button event as well
function reLoad()
    TreeView1:Clear()
    if TreeView1:LoadXML(FileNameEdit1.FileName) then else VCL.ShowMessage("ERROR") end
end
BitBtn1.OnClick = "reLoad"



-- Finally the TreeViewClick event handler, the original ListView replaced with more flexible StringGrid
function OnTreeClick(s)
    if s:Selected() then
        ListView1:Clear()
        ListView1:LoadRowFromTable(0,{"Name","Value"})
        t = s:GetDOMNode(s:Selected())
        if t then
            for k,v in pairs(t) do          
                if type(v)=="table" then
                    for kk,vv in pairs(v) do
                        -- use addrow(n) to insert at position instead of addrow()
                        ListView1:LoadRowFromTable(ListView1:AddRow(1),{kk,vv})
                    end
                else
                    if k=="Name" then
                        Edit1.Text= v or ""
                    elseif k=="Value" then
                        Edit2.Text= v or ""
                    end                 
                end
            end
        end
    end
end
Posted by Janos Bali 2014-04-10 | Draft

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.