Recent

Author Topic: Is it possible to dynamically create dialog box from script/xml file?  (Read 3026 times)

rickg

  • New member
  • *
  • Posts: 5
I would like to dynamically generate simple layouts/dialog boxes defined in xml or configuration files instead of manually setting it up, for example

<dialog>
  <edit label="a" text="1"/>
  <edit label="b" text="2"/>
  <edit label="c" text="3"/>

  <button text="OK"/>
  <button text="Cancel"/>
</dialog>

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

  • Hero Member
  • *****
  • Posts: 1218
Re: Is it possible to dynamically create dialog box from script/xml file?
« Reply #1 on: August 15, 2020, 02:39:19 pm »
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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

rickg

  • New member
  • *
  • Posts: 5
Re: Is it possible to dynamically create dialog box from script/xml file?
« Reply #2 on: August 15, 2020, 03:00:47 pm »
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.
« Last Edit: August 15, 2020, 03:05:06 pm by rickg »

Handoko

  • Hero Member
  • *****
  • Posts: 3752
  • My goal: build my own game engine using Lazarus
Re: Is it possible to dynamically create dialog box from script/xml file?
« Reply #3 on: August 15, 2020, 03:08:01 pm »
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

  • Hero Member
  • *****
  • Posts: 1218
Re: Is it possible to dynamically create dialog box from script/xml file?
« Reply #4 on: August 15, 2020, 04:09:57 pm »
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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

jamie

  • Hero Member
  • *****
  • Posts: 3518
Re: Is it possible to dynamically create dialog box from script/xml file?
« Reply #5 on: August 15, 2020, 05:39:41 pm »
I would like to dynamically generate simple layouts/dialog boxes defined in xml or configuration files instead of manually setting it up, for example

<dialog>
  <edit label="a" text="1"/>
  <edit label="b" text="2"/>
  <edit label="c" text="3"/>

  <button text="OK"/>
  <button text="Cancel"/>

</dialog>
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?
The only true wisdom is knowing you know nothing

Leledumbo

  • Hero Member
  • *****
  • Posts: 8266
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Is it possible to dynamically create dialog box from script/xml file?
« Reply #6 on: August 16, 2020, 01:18:22 pm »
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

  • Hero Member
  • *****
  • Posts: 3517
Re: Is it possible to dynamically create dialog box from script/xml file?
« Reply #7 on: August 16, 2020, 06:27:04 pm »
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

  • New member
  • *
  • Posts: 5
Re: Is it possible to dynamically create dialog box from script/xml file?
« Reply #8 on: August 17, 2020, 03:38:21 pm »
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

  • Hero Member
  • *****
  • Posts: 3518
Re: Is it possible to dynamically create dialog box from script/xml file?
« Reply #9 on: August 17, 2020, 11:35:08 pm »
Looks a lot like html with maybe some JS in it..

I've seen browsers used many times for doing local processing.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018