Possible bug, TTreeNode.Items.Data data disappears in DFM and LFM files lazarus / 9-Editor ---------------------------------------------------------------------- max555 · 2025-01-02 15:06 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 · 2025-01-02 16:55 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. ---------------------------------------------------------------------- max555 · 2025-01-02 17:28 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 · 2025-01-02 17:33 PS If I create original Lazarus form, it looks the same Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i object Form1: TForm1  Left = 248  Height = 462  Top = 145  Width = 611  Caption = 'Form1'  ClientHeight = 462  ClientWidth = 611  LCLVersion = '3.4.0.0'  object TreeView1: TTreeView    Left = 27    Height = 428  Top = 20    Width = 565    TabOrder = 0    Items.Data = {      F9FFFFFF020002000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF010000000000      000001050000004974656D30FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF01000000      0000000001050000004974656D31FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000      00000000000000050000004974656D32FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF      010000000000000001050000004974656D33FFFFFFFFFFFFFFFFFFFFFFFFFFFF      FFFF010000000000000001050000004974656D34FFFFFFFFFFFFFFFFFFFFFFFF      FFFFFFFF000000000000000000050000004974656D35    }  endend and so far it does not remove this property by itself ---------------------------------------------------------------------- wp · 2025-01-02 22:18 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. ---------------------------------------------------------------------- max555 · 2025-01-03 18:18 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 QuoteUnable 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? ---------------------------------------------------------------------- wp · 2025-01-03 18:49 Quote from: max555 on January 03, 2025, 07:18:03 pmProblem 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). Quote from: max555 on January 03, 2025, 07:18:03 pmhow 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. ---------------------------------------------------------------------- wp · 2025-01-04 11:56 Quote from: max555 on January 02, 2025, 04:06:27 pm1) 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/free pascal.org/lazarus/lazarus/-/issues/25098#note_2281669353 Quote from: max555 on January 02, 2025, 04:06:27 pm2) 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.