Recent

Author Topic: The TTreeView Items.Data format in lfm file  (Read 4045 times)

isml

  • New Member
  • *
  • Posts: 15
The TTreeView Items.Data format in lfm file
« on: March 18, 2018, 01:32:48 pm »
Hi, everyone!
    I want to parse the lfm file, and I find the TTreeView's Items.Data is in Hex Format:

  object TreeView1: TTreeView
    Items.Data = {
      F9FFFFFF020001000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF020000000000
      000001020000004141FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000
      0000020000004131FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000
      00020000004132
    }

    Is there any document about this hex data? Thanks in advance

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: The TTreeView Items.Data format in lfm file
« Reply #1 on: March 18, 2018, 01:52:34 pm »
Hex is a base 16 number, which means for each letter it gives you 16 different values..

0..9, ABCDEF

A byte has 8 bits, the lower 4 bits is the right side of the group of two letters and the upper 4 bits is the
left side letter..

 the right letter is the lower nibble (4 bits) and the left side is the upper nibble (4 bits);

 with 4 bits you get 16 different values..

 Since each bit has only two states 0, 1 we can do this.

 2 ^ 4 = 16

 with your example there..

 every two letters are one byte..

 so if you extract every two characters into a string use the StrToINt('$'+Copy(MyHexString,1,2));
that should return the integer value..

 And then move to the next two characters to fetch the next number.

 Remember, every two letters is a byte..

 if you need example to extract that whole string into a block just ask
 
 there could already be a function for it..
The only true wisdom is knowing you know nothing

isml

  • New Member
  • *
  • Posts: 15
Re: The TTreeView Items.Data format in lfm file
« Reply #2 on: March 18, 2018, 02:03:07 pm »
Thanks for your reply.
Actually, I am using another programming language to parse this lfm file. So I need the document of this hex data. The treeview data in my example is like this in designer:

AA
    A1
    A2

and I want to parse AA,A1,A2 and their relationship from the hex data.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: The TTreeView Items.Data format in lfm file
« Reply #3 on: March 18, 2018, 02:30:02 pm »
The Items in a TreeView are the Array of TTreeNodes.

I suspect they are all grouped together in a single cluster in the lfm file for convenience

 You would need to know the number of TreeNode's in that cluster to partition it then you would
need to know the internal format of the TreeNode storage...  It could be the standard windows format, that
I can't tell you.

 The TTreenode has a Data property (Pointer) which points to the whole contents of that node.

 so it's possible they got all grouped together..

 You would need to know the internal format of the TtreeNode and for that I guess you would need to
install Lazarus and then look at the source files to see how the data is laid out..
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: The TTreeView Items.Data format in lfm file
« Reply #4 on: March 18, 2018, 03:22:11 pm »
I found some data for you.
Code: Pascal  [Select][+][-]
  1. procedure TTreeNodes.WriteData(Stream: TStream);
  2. var
  3.   ANode: TTreeNode;
  4.   MagicNumber: integer;
  5. begin
  6.   // -7 for lcl stream
  7.   MagicNumber:=LCLStreamID;
  8.   Stream.WriteBuffer(MagicNumber,SizeOf(MagicNumber));
  9.   // write stream version
  10.   Stream.WriteBuffer(TTreeNodeStreamVersion,SizeOf(Word));
  11.   // write top level node count
  12.   Stream.WriteBuffer(FTopLvlCount, SizeOf(Integer));
  13.   // write all nodes recursively
  14.   ANode := GetFirstNode;
  15.   while ANode <> nil do begin
  16.     ANode.WriteData(Stream);
  17.     ANode := ANode.GetNextSibling;
  18.   end;
  19. end;                  
  20.  
Apparently this is how the data is written out.

 The first magic number does correspond to the $F9FFFFFF;
it's written backwards of course..
the first value is an integer (4 bytes), 8 characters of hex but as you read the stream the F9 ends up on the right side
because that is the lower nibble.

 So -7 = $FFFFFFF9

 This number indicates a Lazarus version.

 The next group is a WORD (2 bytes, 4 characters)..

 This is the Tree Node Stream Version..

 after that.
 Top level count of nodes which is a Integer (4 bytes, 8 Characters).

after that, follows the data of each Node starting from the FirstNode going through the siblings

You need to look at the TTreeNode.WriteData or ReadData to see how the information is interpreted ..

The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: The TTreeView Items.Data format in lfm file
« Reply #5 on: March 18, 2018, 03:50:38 pm »
Code: Pascal  [Select][+][-]
  1. procedure TTreeNode.WriteData(Stream: TStream);
  2. var
  3.   i: integer;
  4.   Info: TTreeNodeInfo;
  5. begin
  6.   Info.ImageIndex := ImageIndex;
  7.   Info.SelectedIndex := SelectedIndex;
  8.   Info.OverlayIndex := OverlayIndex;
  9.   Info.StateIndex := StateIndex;
  10.   Info.Height := FHeight;
  11.   Info.Count := Count;
  12.   Info.Expanded := Expanded;
  13.   Info.TextLen := Length(Text);
  14.   Stream.WriteBuffer(Info, SizeOf(TTreeNodeInfo));
  15.   if Text<>'' then
  16.     Stream.Write(FText[1],length(Text));
  17.   for i := 0 to Count - 1 do
  18.     Items[i].WriteData(Stream);
  19. end;                                              
  20.  

This is how the nodes are written following the main start .
Code: Pascal  [Select][+][-]
  1.  
  2.   TTreeNodeInfo = packed record
  3.     ImageIndex: Integer;
  4.     SelectedIndex: Integer;
  5.     StateIndex: Integer;
  6.     OverlayIndex: Integer;
  7.     Count: Integer;
  8.     Height: integer;
  9.     Expanded: boolean;
  10.     TextLen: integer;
  11.     // here follows the text
  12.   end;                        
  13.  
and that is the format for each node..
text will be appended so this is not a uniform block.
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: The TTreeView Items.Data format in lfm file
« Reply #6 on: March 18, 2018, 04:08:14 pm »
Two remarks:
- The specification for lfm's are subject to change and depend in the Lazarus version. Almost every major version is different.
- What to you want with it? E.g. if you want to use the format in another language make sure it is a binary compiled language: the lfm files are source code and as such the linker exception will not apply to languages like e.g. python etc. if you want to use the format to generate forms. You are then subject to the gpl. So beware and remember that: it can be an issue if or when you want to use it commercially. It has to be compiled in some way.
Specialize a type, not a var.

isml

  • New Member
  • *
  • Posts: 15
Re: The TTreeView Items.Data format in lfm file
« Reply #7 on: March 19, 2018, 03:13:26 am »
Thanks for all the reply.
I want to use Lazarus as a designer, and then parse the lfm and convert to another language's ui code. Dose it violate gpl?

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: The TTreeView Items.Data format in lfm file
« Reply #8 on: March 19, 2018, 07:07:48 am »
Thanks for all the reply.
I want to use Lazarus as a designer, and then parse the lfm and convert to another language's ui code. Dose it violate gpl?
You can parse your own .lfm files, no problem.
I wonder why you want to do so. Does the other system not have a GUI designer?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: The TTreeView Items.Data format in lfm file
« Reply #9 on: March 19, 2018, 08:00:50 am »
Thanks for all the reply.
I want to use Lazarus as a designer, and then parse the lfm and convert to another language's ui code. Dose it violate gpl?
You can parse your own .lfm files, no problem.
I wonder why you want to do so. Does the other system not have a GUI designer?
Imho there is a problem when you distribute those lfm files: that is distributing sourcecode.
But if you parse it and generate code from it there is no problem in distributing that generated code.
Specialize a type, not a var.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: The TTreeView Items.Data format in lfm file
« Reply #10 on: March 19, 2018, 08:17:43 am »
Imho there is a problem when you distribute those lfm files: that is distributing sourcecode.
Yes but it is his own source code if I understood correctly. He can do whatever he wants with it.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: The TTreeView Items.Data format in lfm file
« Reply #11 on: March 19, 2018, 09:38:14 am »
Yes but it is his own source code if I understood correctly. He can do whatever he wants with it.
If that is the case: of course.
Specialize a type, not a var.

isml

  • New Member
  • *
  • Posts: 15
Re: The TTreeView Items.Data format in lfm file
« Reply #12 on: March 20, 2018, 03:19:13 am »
Yes, not every ui library has a good designer, and many does not even have one.I think lazarus is really a wonderful designer, but I am not familiar with freepascal. I just want to parse lfm directly to another language's ui code and do not need lfm when running.
Thanks again for all the help.

 

TinyPortal © 2005-2018