How to save tree? lazarus / 3-General ---------------------------------------------------------------------- kernel · 2009-11-26 15:17 Hi I thought it would be like code below, but it doesn't work. What's wrong? Thanks for help. var   Tree1 : Tree   f : File of Tree; begin   assignFile(f, 'file.dat');   rewrite(f);   Seek(f,0);   write(f, Tree1);   closeFile(f); end; ---------------------------------------------------------------------- theo · 2009-11-26 16:58 Whrere / how is "Tree" defined? ---------------------------------------------------------------------- Blaazen · 2009-11-26 17:11 Hi, I don't know what is exactly your type Tree, but probably it is some tree structure with your data (like AVL tree). It means if you try to save Tree to file this way you only save some pointers which are used for realization of Tree and some pointers to your data, but not data itself. I think solution is go step by step through Tree and save all data to file (probably it is records). When file is opened next time, you create new empty Tree and you add new elements and make them points to your data step by step until you reach end of file. I think it is similar to all dynamic structures, it is simplier for lists (one or bi-directional) and more difficult for Trees (because they are usually sorted). ---------------------------------------------------------------------- Troodon · 2009-11-26 18:29 If Tree is a pointer to a record then try write(f, Tree1^). But if Tree is a data structure that contains pointers then, like Blaazen said, in order to save the data to a file you need to traverse the structure.