Recent

Author Topic: Convert LFM to XML (or JSON)  (Read 510 times)

pcurtis

  • Full Member
  • ***
  • Posts: 203
Convert LFM to XML (or JSON)
« on: September 02, 2020, 08:56:26 am »
Hi All,

I'm looking for a way to display a LFM file in a treeview.

My idea is to convert the LFM file to either a XML or JSON file and then populate a treeview.

XML (JSON) to treeview is no problem, but I cannot find anything to convert the LFM file.

Can anyone help? (Code samples or ideas)

Thanks in advance.
Windows 10 / Linux Mint 20
Laz 2.10.0
FPC 3.2.0

PascalDragon

  • Hero Member
  • *****
  • Posts: 2131
  • Compiler Developer
Re: Convert LFM to XML (or JSON)
« Reply #1 on: September 02, 2020, 09:07:17 am »
Why do you need to convert it to XML or JSON? You read the LFM file and directly create the nodes for your treeview from that.

pcurtis

  • Full Member
  • ***
  • Posts: 203
Re: Convert LFM to XML (or JSON)
« Reply #2 on: September 02, 2020, 09:20:48 am »
Thanks for the tip.

Do you know of any sample code?
Windows 10 / Linux Mint 20
Laz 2.10.0
FPC 3.2.0

PascalDragon

  • Hero Member
  • *****
  • Posts: 2131
  • Compiler Developer
Re: Convert LFM to XML (or JSON)
« Reply #3 on: September 02, 2020, 09:32:28 am »
You should probably take a look at the code of Classes.ObjectTextToResource and Classes.ObjectTextToBinary (both declared in $fpc/rtl/objpas/classes/classesh.inc and defined in $fpc/rtl/objpas/classes/classes.inc.

pcurtis

  • Full Member
  • ***
  • Posts: 203
Re: Convert LFM to XML (or JSON)
« Reply #4 on: September 02, 2020, 09:39:09 am »
Way over my head
Windows 10 / Linux Mint 20
Laz 2.10.0
FPC 3.2.0

jamie

  • Hero Member
  • *****
  • Posts: 3526
Re: Convert LFM to XML (or JSON)
« Reply #5 on: September 02, 2020, 12:55:24 pm »
Its not that bad, that is how it's stored in the program file

Its in a different format so that it can be read faster when streaming the items to your properties..

The items he showed you are those involved to convert from the format used to store the property items over to a text base format..

 When you open the LFM file it is already a text base file and if you go to the TOOLS menu there is a checker option there to examine the file for issues.

« Last Edit: September 02, 2020, 12:59:54 pm by jamie »
The only true wisdom is knowing you know nothing

PascalDragon

  • Hero Member
  • *****
  • Posts: 2131
  • Compiler Developer
Re: Convert LFM to XML (or JSON)
« Reply #6 on: September 02, 2020, 01:27:35 pm »
The items he showed you are those involved to convert from the format used to store the property items over to a text base format..

No, the other way round. That is the code that is used to parse LFM files to embed them in the resource. At least the parser needs to be done by pcurtis anyway (and for that the code from Classes can be reused).

jamie

  • Hero Member
  • *****
  • Posts: 3526
Re: Convert LFM to XML (or JSON)
« Reply #7 on: September 02, 2020, 02:28:55 pm »
The thought the LFM was stored In the resource in a compressed format not raw strings like that ?

If that being the case I see one reason for the FILES getting so large.
The only true wisdom is knowing you know nothing

howardpc

  • Hero Member
  • *****
  • Posts: 3520
Re: Convert LFM to XML (or JSON)
« Reply #8 on: September 02, 2020, 03:39:42 pm »
The attached project is a simple-minded approach to putting the outline of an lfm into a treeview.
It is hardly tested, so probably buggy, but might get you started on a fuller implementation.

pcurtis

  • Full Member
  • ***
  • Posts: 203
Re: Convert LFM to XML (or JSON)
« Reply #9 on: September 02, 2020, 04:00:40 pm »
@howardpc - Thank you so much.
Windows 10 / Linux Mint 20
Laz 2.10.0
FPC 3.2.0

dsiders

  • Sr. Member
  • ****
  • Posts: 374
Re: Convert LFM to XML (or JSON)
« Reply #10 on: September 02, 2020, 04:03:57 pm »
The thought the LFM was stored In the resource in a compressed format not raw strings like that ?

If that being the case I see one reason for the FILES getting so large.

The only thing compressed about an LFM file is the representation of image data (as hex).
Lazarus 2.1 (SVN) / FPC 3.0.4 / FPC 3.2.0 / x86-win64 / Windows 8.1

pcurtis

  • Full Member
  • ***
  • Posts: 203
Re: Convert LFM to XML (or JSON)
« Reply #11 on: September 02, 2020, 04:59:23 pm »
How would I go about adding the properties for each object to the treeview? Otherwise it works fine.
Windows 10 / Linux Mint 20
Laz 2.10.0
FPC 3.2.0

howardpc

  • Hero Member
  • *****
  • Posts: 3520
Re: Convert LFM to XML (or JSON)
« Reply #12 on: September 02, 2020, 05:33:59 pm »
I think the attached may do what you want.
If not, adapt it as needed.

pcurtis

  • Full Member
  • ***
  • Posts: 203
Re: Convert LFM to XML (or JSON)
« Reply #13 on: September 02, 2020, 06:35:42 pm »
Perfect. Thank you.
Windows 10 / Linux Mint 20
Laz 2.10.0
FPC 3.2.0

PascalDragon

  • Hero Member
  • *****
  • Posts: 2131
  • Compiler Developer
Re: Convert LFM to XML (or JSON)
« Reply #14 on: September 03, 2020, 09:44:38 am »
The thought the LFM was stored In the resource in a compressed format not raw strings like that ?

If that being the case I see one reason for the FILES getting so large.

I did not say that the data in the resources is not a binary format (which it is). I said that the function I pointed to converts from the text format of the LFM to the binary format. You however said that these functions are for the other way round (namely binary format to text).

Also the size of the LFM files even if they'd be stored as text isn't the cause for the size of LCL applications. For one FPC stores the debug information - if enabled - inside the executable by default leading to a much larger binary size (e.g. a LCL application with an empty form will have around 20 MB). Also the abstractions of the LCL to cater for the different widgetsets leads to code that is rather difficult to nicely smartlink, thus the base size of an LCL application is around 1 - 3 MB, but it will grow much slower with each form added.

 

TinyPortal © 2005-2018