Recent

Author Topic: Possible bug, TTreeNode.Items.Data data disappears in DFM and LFM files  (Read 3977 times)

max555

  • New Member
  • *
  • Posts: 12
Hello,
Looks like there are couple bugs in Lazarus 3.4 for Linux

1) menu Tool -> Delphi conversion -> Convert Delphi unit to Lazarus unit
This tool often removes Items.Data property, at least for TTreeNode.Items.Data. I tried several forms with the same result

2) Ok, I copied TTreeNode.Items.Data from original DFM file into LFM, and there is bug #2
- I modified LFM, saved file, compiled project - error, still no TTreeNode.Items.Data in the module.
- Ok, I opened and closed source files in IDE, I removed .o, .ppu, .lfm files in output directory, recompiled project - same error, still no TTreeNode.Items.Data in the module.
The only way to fix the problem - restart Lazarus IDE

3) But its not over. Everything compiled and worked and then error returned by itself - TTreeNode.Items.Data was removed from .LFM file again.
Problem #3 related to 1 LFM file so far, while problems #1 and #2 reproduced on several different forms.

Thank you

wp

  • Hero Member
  • *****
  • Posts: 12525
Re: Possible bug, TTreeNode.Items.Data data disappears in DFM and LFM files
« Reply #1 on: January 02, 2025, 05:55:34 pm »
Please be more specific and exact. To my knowledge, there is no TTreeNode.Items.Data property, only a TTreeNode.Data. Is it that what you mean?

I would be surprised when Lazarus streams TTreeNode.Data at all since this is a pointer which will point to nowhere after reading. How even can you assign something to TreeNode.Data at designtime to be streamed since there is no GUI for that?

Post a small sample project demonstrating the issue.
« Last Edit: January 02, 2025, 06:01:50 pm by wp »

max555

  • New Member
  • *
  • Posts: 12
Re: Possible bug, TTreeNode.Items.Data data disappears in DFM and LFM files
« Reply #2 on: January 02, 2025, 06:28:19 pm »
Yes, looks like there is no such property but somehow it works and application load tree items when specified in LFM file.
Delphi stores items in this property as hex string
It looks like
  object LargeTree: TTreeView
    Left = 0
    Top = 0
    Width = 154
    Height = 285
    Items.Data = {
      1200000024000000000000000000000000000000FFFFFFFF0000000000000000
      0B507265666572656E63657321000000000000000000000001000000FFFFFFFF
      0000000000000000084265686176696F72200000000000000000000000020000
      00FFFFFFFF000000000100000007537461727475702000000000000000000000
      0000FFFFFFFF00000000000000000C436F6D70616374206C6F67732600000000
      0000000000000009000000FFFFFFFF00000000000000000D484D207379737465
      ....}
So compiled project is able to load data correctly but converter and sometimes IDE removes such data

max555

  • New Member
  • *
  • Posts: 12
Re: Possible bug, TTreeNode.Items.Data data disappears in DFM and LFM files
« Reply #3 on: January 02, 2025, 06:33:09 pm »
PS
If I create original Lazarus form, it looks the same

Code: Pascal  [Select][+][-]
  1. object Form1: TForm1
  2.   Left = 248
  3.   Height = 462
  4.   Top = 145
  5.   Width = 611
  6.   Caption = 'Form1'
  7.   ClientHeight = 462
  8.   ClientWidth = 611
  9.   LCLVersion = '3.4.0.0'
  10.   object TreeView1: TTreeView
  11.     Left = 27
  12.     Height = 428
  13.     Top = 20
  14.     Width = 565
  15.     TabOrder = 0
  16.     Items.Data = {
  17.       F9FFFFFF020002000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF010000000000
  18.       000001050000004974656D30FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF01000000
  19.       0000000001050000004974656D31FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000
  20.       00000000000000050000004974656D32FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  21.       010000000000000001050000004974656D33FFFFFFFFFFFFFFFFFFFFFFFFFFFF
  22.       FFFF010000000000000001050000004974656D34FFFFFFFFFFFFFFFFFFFFFFFF
  23.       FFFFFFFF000000000000000000050000004974656D35
  24.     }
  25.   end
  26. end

and so far it does not remove this property by itself

wp

  • Hero Member
  • *****
  • Posts: 12525
Re: Possible bug, TTreeNode.Items.Data data disappears in DFM and LFM files
« Reply #4 on: January 02, 2025, 11:18:59 pm »
Now I understand. The node TreeView.Items.Data in the lfm file is a compact presentation of the nodes, and it seems that Delphi and Lazarus are doing it differently: Lazarus begins with a "MagicNumber" (-7 = 'F9FFFFFF'), a version identifcation, the number of top-level nodes and then the nodes themselves (TTreeNodeInfo), while Delphi only writes the number of nodes and then the nodes as TDelphiNodeInfo records (see TTreeNodes.ReadData and TTreeNode.ReadData in treeview.inc). The lfm reader of Lazarus is able to detect the originator and read Delphi files accordingly. But: The reader only seems to know the format of Delphi 7. When I create a form with Delphi XE 11, the node is no longer called Items.Data, but Items.NodeData. I don't know when the switch occured, probably when the Unicode was introduced, but the difference is fatal. Lazarus does not know the identifier "Items.NodeData" and refuses to load this part of the dfm file... Even Delphi 7 cannot read its files once they were opened by XE11.

I'll have to investigate more details - maybe there is a way to fix the new Delphi files. Or I'll write a bug-report so that somebody else can have a look at it.
« Last Edit: January 04, 2025, 12:49:37 pm by wp »

max555

  • New Member
  • *
  • Posts: 12
Re: Possible bug, TTreeNode.Items.Data data disappears in DFM and LFM files
« Reply #5 on: January 03, 2025, 07:18:03 pm »
Thank you.
Problem actually related to Delphi 7 files.
1) one file was damaged after conversion (missed Items.Data) but I copied Items.Data from DFM and it works fine;
2) another file was damaged after conversion the same way, I copied Items.Data from DFM, project compiled, works, but IDE removed Items.Data again and again so I have to insert this data again and use chmod a-w to make file read only.

Probably 2nd problem happens because I am copying data from DFM file, without Magic number.
But somehow this works fine for 1st file.

I tried to reproduce problem today, removed "read-only" flag, copied Items.Data from DFM into LFM (without Magic number) and this time IDE opens PAS file but does not open form at all, shows error
Quote
Unable to convert text from data of file "..lfm" into binary stream. (Wrong token symbol: INLINE expected but end found (at 1000,4, stream offset 00009EAA))

Probably that's correct error but then how to convert DFM Items.Data into LFM Items.Data properly? Just insert magic number 'F9FFFFFF' + a version identifcation + the number of top-level nodes?
« Last Edit: January 03, 2025, 07:31:47 pm by max555 »

wp

  • Hero Member
  • *****
  • Posts: 12525
Re: Possible bug, TTreeNode.Items.Data data disappears in DFM and LFM files
« Reply #6 on: January 03, 2025, 07:49:42 pm »
Problem actually related to Delphi 7 files.
Thanks for the information. Then I was chasing after some different bug, no problem. Filed a bug report for mine (https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/41303), did some reverse engineering, and now I am able to read Treeview dfm files written by newer Dephi versions. Committed to Laz/main.

Maybe you take a look at the "Steps to reproduce", it gives instructions on how I convert Delphi projects to Lazarus projects - the converter seems to be broken currently (I am using Laz/main).

how to convert DFM Items.Data into LFM Items.Data properly? Just insert magic number 'F9FFFFFF' + a version identifcation + the number of top-level nodes?
No, there are several differences in the "NodeInfo records between these two worlds. But Lazarus is able to detect whether a Items.Data record was written by Delphi 7 or by Lazarus and thus applies the correct record structure. So, please don't touch this part of the dfm/lfm file.
« Last Edit: January 04, 2025, 12:46:53 pm by wp »

wp

  • Hero Member
  • *****
  • Posts: 12525
Re: Possible bug, TTreeNode.Items.Data data disappears in DFM and LFM files
« Reply #7 on: January 04, 2025, 12:56:27 pm »
1) menu Tool -> Delphi conversion -> Convert Delphi unit to Lazarus unit
This tool often removes Items.Data property, at least for TTreeNode.Items.Data. I tried several forms with the same result
Not sure, maybe it depends on the converter settings. Find the setting of a successful conversion that I did today at https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/25098#note_2281669353

2) Ok, I copied TTreeNode.Items.Data from original DFM file into LFM, and there is bug #2
- I modified LFM, saved file, compiled project - error, still no TTreeNode.Items.Data in the module.
- Ok, I opened and closed source files in IDE, I removed .o, .ppu, .lfm files in output directory, recompiled project - same error, still no TTreeNode.Items.Data in the module.
The only way to fix the problem - restart Lazarus IDE
When you manually edit the lfm file do not do this with the IDE running because it also has a copy of the file in the output directory. Always close the IDE, and edit the file in an external editor.

 

TinyPortal © 2005-2018