Recent

Author Topic: Howto save tlist with object distinct in a file?  (Read 1801 times)

fsemonetti

  • Newbie
  • Posts: 1
Howto save tlist with object distinct in a file?
« on: September 07, 2021, 02:01:08 am »
Good night! first, sorry about my english, my native language is portuguese..

Look under sample :

Code: Pascal  [Select][+][-]
  1. Tline = class
  2.           pa : tpoint;
  3.           color :  integer;
  4.           End
  5.  
  6. Tbox = classs
  7.           pa,pb : tpoint;
  8.           Color : integer;
  9.           End;
  10.  
  11.   ....
  12.             Var
  13.            Lista : tlist;
  14.           a       : tline;
  15.           b       : tbox;
  16.  
  17.      Begin
  18.      lista:=tlist.create();
  19.     a:=tline.create();
  20.     b:=tbox.create();
  21.  
  22.     lista.add(a);
  23.     lista.add(b);

   how save lista to file ?

[Edited to add code tags: please see How to Use the Forum.]
« Last Edit: September 07, 2021, 03:35:41 am by trev »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1627
  • Former Delphi 1-7, 10.2 user
Re: Howto save tlist with object distinct in a file?
« Reply #1 on: September 07, 2021, 03:33:58 am »
Welcome!

ListA.Items.SaveToFile('lista.txt');

Sorry - should have paid attention to the content of TList.
« Last Edit: September 07, 2021, 12:00:15 pm by trev »
Lazarus 2.3 + FPC 3.3.1 2021-10-19 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.3 + FPC 3.3.1 2021-09-21 macOS 11.6 aarch64 Xcode 13
Lazarus 2.3 2021-08-11 FPC 3.2.2 FreeBSD 13.0 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

Bart

  • Hero Member
  • *****
  • Posts: 4477
    • Bart en Mariska's Webstek
Re: Howto save tlist with object distinct in a file?
« Reply #2 on: September 07, 2021, 10:11:48 am »
Code: Pascal  [Select][+][-]
  1. ListA.Items.SaveToFile('lista.txt');

I don't think this will magiacally write the infor that fsemonetti needs* to the file, I suspects it writes pointers (untested hypothesis).

* I assume he wants the points, (coördinates) and colors of each box and each line in his file.
Not a difficult task, but I suspect not as trivial as you suggest.

Bart

 

TinyPortal © 2005-2018