Recent

Author Topic: TTreeView with justified child node content (like in grids with cells)  (Read 2860 times)

ArminLinder

  • Sr. Member
  • ****
  • Posts: 316
  • Keep it simple.
Hi,

what I need is much like the attched example: a treelike structure, with the children at a certain level showing tabular data. As you can see in the sample the programmer took the easy way out and joined all data into one string, which gives an unacceptable look, since within a string he cannot justify the various elements (oh boy, how many times I wished that elements containing text output would support the good old "tab" character).

Anyway, is there a ready made component, a sample or a documented solution for this? In this case, "Windows only" will suffice.

Thnx, Armin

P.S. IMHO a completely different approach would be also possible: take a StringGrid and integrate the tree structure by putting the tree structure into the leftmost rows, and use kind of cell merging mechnism to let the captions write over the cells to the right. Whichever way a component is available, I don't care much.

P.P.S. I had a look at VirtualTreeView, which looks promising, but boy, that thing is heavy ...
« Last Edit: April 27, 2021, 03:33:29 pm by Nimral »
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

balazsszekely

  • Guest
@Nimral

If you need a tree with multiple column go with VST.  You can achieve the look from screenshot in 10 minutes or so. Plus it's cross platform.

PS: If you need help, just let me know. :)
« Last Edit: April 27, 2021, 04:34:58 pm by GetMem »

ArminLinder

  • Sr. Member
  • ****
  • Posts: 316
  • Keep it simple.
I remember having tried VST some time ago, and the project barely survived.

In general it worked, but was full of little glitches which in total made working with it a pain, and hunting for tipps and fixes ate deeply into the prjoect's time schedule.

Are you sure it's worth trying again? if I do, which one on git is the preferred version? The "master", or the lastest "Release Version 5.5.3 - LCL Release 2"?

Armin.
« Last Edit: April 28, 2021, 11:20:53 am by Nimral »
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1192
  • Professional amateur ;-P
Hey Armin,

if I do, which one on git is the preferred version? The "master", or the lastest "Release Version 5.5.3 - LCL Release 2"?

If you have the OPM(Online Package Manager) installed, it can install a pretty good version of VST and it will allow for further updates once the maintainer of VST grabs GetMem's attention to list a new version :)

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

balazsszekely

  • Guest
@Nimral
Quote
Are you sure it's worth trying again?
Yes, I'm pretty sure that VST is one of the best choice for a multiple column tree.

Quote
In general it worked, but was full of little glitches which in total made working with it a pain, and hunting for tipps and fixes ate deeply into the prjoect's time schedule.
The learning curve for VST is steep. You have to decide if the invested time is worth it. Unfortunately I cannot help here.

Quote
if I do, which one on git is the preferred version? The "master", or the lastest "Release Version 5.5.3 - LCL Release 2"?
Both Lazarus 2.0.12 and Lazarus Trunk have a preinstalled version of VST, a fork of 5.5.3.  As @Gus already mentioned, OPM also contains a VTV, which should be the same with the gitbhub version.

PS: If you are unsure, please do a forum search. You will find a lot of examples with VST.

ArminLinder

  • Sr. Member
  • ****
  • Posts: 316
  • Keep it simple.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

ArminLinder

  • Sr. Member
  • ****
  • Posts: 316
  • Keep it simple.
 >:( 10 Minutes?  >:(

After more than 15 hours, and absolutely no progress, except approx 10 trial projects which have all failed miserably in early stages when I got lost somewhere in one of the many dark corners, and ended up staring at empty or mangled grids with no idea how this could happen since I tried to follow the many tuts and docs around, including the 2613 page monster at https://documentation.help/VirtualTreeview/documentation.pdf I am at the edge of giving up.

This damn thing is killing me, exactly like last time when I tried to use it.

Alternatives?

Armin.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

jamie

  • Hero Member
  • *****
  • Posts: 6953
why don't you handle the OnCustomDrawItem

There are at various other places in custom drawings you can split the line of text so that you can Tab column align your numbers all to the right. Because there you also need to do the graphics.
The only true wisdom is knowing you know nothing

ArminLinder

  • Sr. Member
  • ****
  • Posts: 316
  • Keep it simple.
Ok, I need to give up. 1:30 in the morning, and I have been staring at 30 lines of code for 3 hours now, and cannot find out what's wrong.

I can add roots. Great, except that only 2 columns get displayed, it should be 4.
I can focus and select

in column 3 sometimes random text apppears --> I corrupted the memory, somehow.
deleting one or more nodes crashes the program
adding a child node crashes the program.

WTF is going on here?

Lazarus 2.0.12 x32 on Windows 10x64, VTV 5.5.3.1

Armin.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

balazsszekely

  • Guest
@Nimral

I did a small demo according to the screenshot form the first post. I did try to keep it as simple as possible, sort column is implemented.
Please check the attached project(Lazarus 2.0.12/FPC 3.2.0)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1192
  • Professional amateur ;-P
Re: TTreeView with justified child node content (like in grids with cells)
« Reply #10 on: April 30, 2021, 05:13:54 pm »
Hey Getmem,

Please check the attached project(Lazarus 2.0.12/FPC 3.2.0)

I like your simple approach of one big record for all info.

I usually do something like this:
Code: Pascal  [Select][+][-]
  1. type
  2.   TMyNodeType = (ntUnknown, ntType1, ntType2{...});
  3.   TCommonAncestor = class(TObject)
  4.     FName: String;//<-- Basically for GetNodetext()
  5.   end;
  6.   TType1 = class(TCommonAncestor)
  7.     FTypeOneSpecificField: Integer; //<-- Whateves...
  8.   end;
  9.   TType2 = class(TCommonAncestor)
  10.     FTypeTwoSpecificField: Integer; //<-- Whateves...
  11.   end;
  12.   PMyNode = ^TMyNode;
  13.   TMyNode = record
  14.     NodeType: TMyNodeType;
  15.     NodeData: TCommonAncestor;
  16.   end;

OR

Code: Pascal  [Select][+][-]
  1. type
  2.   TMyNodeType = (ntUnknown, ntType1, ntType2{...});
  3.   TType1 = class(TObject)
  4.     FName: String;//<-- Basically for GetNodetext()
  5.     FTypeOneSpecificField: Integer; //<-- Whateves...
  6.   end;
  7.   TType2 = class(TObject)
  8.     FName: String;//<-- Basically for GetNodetext()
  9.     FTypeTwoSpecificField: Integer; //<-- Whateves...
  10.   end;
  11.   PMyNode = ^TMyNode;
  12.   TMyNode = record
  13.     NodeType: TMyNodeType;
  14.     NodeData: TObject;
  15.   end;

And then type cast according to the MyNode^.NodeType down the code.

And the TType1, TType2, etc I get from ORM or from local filesystem.

Is this a good approach?

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

balazsszekely

  • Guest
@Gus
Quote
I like your simple approach of one big record for all info.
In most cases the nodes tend to be very similar, each has a name, id, parentid, etc. I'm aware that this approach has a small redundancy, but never caused any issues for me.

Quote
ls this a good approach? 
For trees with complex data structure is an excellent idea.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1192
  • Professional amateur ;-P
Hey GetMem,

In most cases the nodes tend to be very similar, each has a name, id, parentid, etc. I'm aware that this approach has a small redundancy, but never caused any issues for me.

I do concur that for such a simple example and/or data structure the added redundancy is negligible.

For trees with complex data structure is an excellent idea.

Uffff, thanks for that. I always suffer from loads of imposter syndrome when I come up with something by myself.
It's good to have my ideas validated by someone I consider a more senior Pascal dev.

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

ArminLinder

  • Sr. Member
  • ****
  • Posts: 316
  • Keep it simple.
Just to make this thread complete ... I found the problem.

Please see the form definition, somehow the OnCreate event handler slipped from the members section into the public section. This won't, unfortunately, trigger any alarm anywhere, but the FormCreate procedure won't ever be called, TreeNodeSize won't be set properly and a SIGSEV will follow soon.

Armin.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

 

TinyPortal © 2005-2018