Is it possible to dynamically create dialog box from script/xml file?
lazarus / 31-LCL
----------------------------------------------------------------------
rickg · 2020-08-15 12:18
I would like to dynamically generate simple layouts/dialog boxes
defined in xml or configuration files instead of manually setting it
up, for example
would generate a dialog box with three edit fields for a, b, c, with
the assigned values which could be edited, and ok and cancel buttons.
I believe I have seen something like this that maybe was a commercial
project, but I can't find anything like it now for FPC/Lazarus. It
there some example how this could be done somewhere?
----------------------------------------------------------------------
MarkMLl · 2020-08-15 12:39
Do you mean "create for the compiler to use (but not using the IDE)"
or "customise at runtime"?
I'm not saying I've got an answer, but I think it's necessary to make
that distinction before anybody else starts thinking about it.
MarkMLl
----------------------------------------------------------------------
rickg · 2020-08-15 13:00
Yes, I meant to customize at runtime. For example, the compiled
program reads the xml form and presents a dialog based on the
information therein, after editing and pressing the ok button the form
is updated with the new data. I realize this might sound like a basic
table, but I'm thinking of more complex dialogs that could be a mix of
edit fields, radio buttons, checkboxes etc. depending on the
requirements.
----------------------------------------------------------------------
Handoko · 2020-08-15 13:08
That's possible but not easy. You need to to know how to create a form
on runtime and understand how to read/update xml files.
----------------------------------------------------------------------
MarkMLl · 2020-08-15 14:09
It would probably be easier if the dialog(ue) were actually one of a
number of predefined patterns designed as forms using the IDE.
MarkMLl
----------------------------------------------------------------------
jamie · 2020-08-15 15:39
Quote from: rickg on August 15, 2020, 02:18:52 pmI would like to
dynamically generate simple layouts/dialog boxes defined in xml or
configuration files instead of manually setting it up, for example
Have you looked at the "Pascal Script" components/Controls already
installed on the palette ?
With that you can load/Run pascal scripts that are very close to being
native.
You should be able to create a dialog with buttons on it, assign
events etc.
would generate a dialog box with three edit fields for a, b, c, with
the assigned values which could be edited, and ok and cancel buttons.
I believe I have seen something like this that maybe was a commercial
project, but I can't find anything like it now for FPC/Lazarus. It
there some example how this could be done somewhere?
----------------------------------------------------------------------
Leledumbo · 2020-08-16 11:18
Like Handoko said, doable but not easy. Shortest route you can take is
to convert your .xml to .lfm at runtime then feed it by calling
ReadComponentRes after creating the form. Of course this will only
create the form with components laid out using default layouting,
unless you also handle them in your XML structure. Last but not least,
don't forget events.
----------------------------------------------------------------------
howardpc · 2020-08-16 16:27
You might like to look at the attached project.
An example CSV-generated dialog and user output shown in a test
program (see images below) were generated from the appended CSV file.
I used CSV because I find it more compact than xml, but obviously the
data format could be changed.
The example code attached is a proof-of-concept rather than a finished
article, but should get you started.
dialog,text=Options,color=clskyblue
label,text=Example Options
dialog,style=bolditalic,size=12,align=alCenter
combo,text=Language:,items=French|German|Dutch|Finnish,itemindex=2
edit,text=file name,labelText=Saved file's name:,texthint=file name
checkbox,text=Show grid hints,checked=Y
edit,text=directory,labelText=Backup directory:,texthint=directory
label,text= Backup,style=bold,size=11,align=alLeft
radio,text=No backup,checked=N
radio,text=Backup in subdirectory,checked=Y
radio,text=Backup using same name + .bak,checked=N
button,text=Cancel,modalResult=mrCancel
button,text=OK,modalResult=mrOK
----------------------------------------------------------------------
rickg · 2020-08-17 13:38
Thanks for all the suggestions by everyone. I'm still quite sure I've
seen a productized solution some time ago (maybe for Delphi), but I
have some options to work with for now.
----------------------------------------------------------------------
jamie · 2020-08-17 21:35
Looks a lot like html with maybe some JS in it..
I've seen browsers used many times for doing local processing.