Storing hierarchal data lazarus / 21-General ---------------------------------------------------------------------- peardox · 2021-03-26 13:32 What's a suitable non-visual way to store hierarchal data? TreeViews etc are available in abundance but I don't wanna display it. I want to store data about some object(s) in a generalized tree structure. All I seem to be able to find is a load of lists and binary trees, none of which are suitable. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-03-26 13:42 Hey Peardox, Well, there's JSON via the fpjson unit. Or you could roll out your own with TObjects for the objects and TFPObjectList for arrays. That's what I do when I un-marshall the TJSONData objects into objects of my own. Cheers, Gus ---------------------------------------------------------------------- avk · 2021-03-26 14:08 There is a generic tree implementation in the GTree module in the fcl- stl package and this one. ---------------------------------------------------------------------- peardox · 2021-03-26 14:42 How about one with documentation? ---------------------------------------------------------------------- avk · 2021-03-26 14:59 If you find any documented tree, please share. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-03-26 15:17 Hey Peardox, Quote from: peardox on March 26, 2021, 03:42:38 pmHow about one with documentation? Well, there isn't a catch all, generic tree, suitable for everything is it? If you want hierarchical anything you have to dictate some ground rules and minimum requirements for data structures possible, etc... You know, like the good folks that wrote the definition of JSON. So if you don't give us a bit of background about your needs, you'll probably only get generic, non helpful answers! What do you say? Give us some more details? Or is it for a super duper hush-hush government secret project? Cheers, Gus PS: You can always study the way Vistual String Treeview does it internally, it's very fast and can manage huge amounts, since it uses pointers to records, but then all nodes must be the same... ---------------------------------------------------------------------- egsuh · 2021-03-29 12:09 What do you mean by "store"? I have a database table, which contains the tree structure. It needs three additional fields --- parent, first child, and next sibling. Well each record has its own distinctive number, so all the fields are integer type. If any node has no parent, its parent field's value is 0. If it is the last node under a parent, both of first child and next sibling would be  0. When I use the data, I restore them into TTreeview, by adding the contents as objects. ---------------------------------------------------------------------- valdir.marcos · 2021-03-29 21:28 Quote from: peardox on March 26, 2021, 02:32:57 pmWhat's a suitable non-visual way to store hierarchal data? TreeViews etc are available in abundance but I don't wanna display it. I want to store data about some object(s) in a generalized tree structure. All I seem to be able to find is a load of lists and binary trees, none of which are suitable.There was a little file named "ANIMAL.PAS" in the old times of Turbo Pascal 2.0 or 3.0. It was a non-visual guessing game. Unfortunately, I don't have that file any more, but it did what you are looking for in a very simple way. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-03-30 17:43 Hey Valdir, Quote from: valdir.marcos on March 29, 2021, 11:28:36 pmThere was a little file named "ANIMAL.PAS" in the old times of Turbo Pascal 2.0 or 3.0. That's funny, it's the next thing I have on my list of porting tasks for the BASIC computer games - 03 Animal. Interesting And by the way, it uses linked binary trees. Every node can only have 2 children, not N, so not that useful for a full tree implementation. Cheers, Gus ---------------------------------------------------------------------- Roland57 · 2021-03-30 20:13 Quote from: peardox on March 26, 2021, 02:32:57 pmI want to store data about some object(s) in a generalized tree structure. Hello! I made for a chess program this unit for managing a tree of opening moves (in fact a list of trees, since there are several roots, several possible first moves). Is it something like that that you need? Here is a little demo, to show you what the program is able to do. 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 var  LTreeList: TTreeList;  begin  LTreeList := TTreeList.Create;    LTreeList.AddLine('e2e4 e7e5 d2d4');  LTreeList.AddLine('e2e4 c7c5');  LTreeList.AddLine('d2d4 d7d5');    WriteLn('"', LTreeList.FindMoveToPlay('', FALSE),          '"');  WriteLn('"', LTreeList.FindMoveToPlay('e2e4', FALSE),      '"');  WriteLn('"', LTreeList.FindMoveToPlay('e2e4 e7e5', FALSE), '"');    LTreeList.SaveToFile('minibook.txt');  LTreeList.SaveToFileCompact('minibook-compact.txt');    LTreeList.Free;