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...
-Use "Save Form as XML" option in Lazarus Ide on a form.
-Check the XML, remove any 'binary' tags. ( yes, this is a bug in lazarus ide )
-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"))()
-- Load button event
function reLoad()
TreeView1:Clear()
if TreeView1:LoadXML(FileNameEdit1.FileName) then else VCL.ShowMessage("ERROR") end
end
BitBtn1.OnClick = "reLoad"
-- The TreeViewClick event handler
-- (ListView replaced with 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
-- DOMNode.NodeName and NodeValue
if k=="Name" then
Edit1.Text= v or ""
elseif k=="Value" then
Edit2.Text= v or ""
end
end
end
end
end
end
TreeView1.OnClick = "OnTreeClick"
-- Finally
XMLReaderForm:ShowModal()
The result is same as the original example...