Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Stringlist or not? Posted by heinrich13 on 30 May 2006 at 6:13 AM
I need to read information from something that are similar to a treeview (but it's not). Each level in the "tree" can have an unknown amount of sublevels and so can each sublevel and so on.

Which is the best way to read and store this information? Can I use Stringlists and how will I do it? Any suggestions?

The information I read will be saved to a textfile like this:

Current context: A
A_1
A_2
A_3
Current context: A_1
A_1.1
A_1.2
A_1.3
.
.
etc

A_1, A_2, A_1.1 etc are sublevels.

/Heinrich
Report
Re: Stringlist or not? Posted by porodoro on 30 May 2006 at 7:21 AM
: I need to read information from something that are similar to a treeview (but it's not). Each level in the "tree" can have an unknown amount of sublevels and so can each sublevel and so on.
:
: Which is the best way to read and store this information? Can I use Stringlists and how will I do it? Any suggestions?
:
: The information I read will be saved to a textfile like this:
:
: Current context: A
: A_1
: A_2
: A_3
: Current context: A_1
: A_1.1
: A_1.2
: A_1.3
: .
: .
: etc
:
: A_1, A_2, A_1.1 etc are sublevels.
:
: /Heinrich
:
Use this to create a str list:

public
(global VARIABLE--)
var List:Tstringlist;

----------------------------

list := tstringlist.create;

list.clear;

list.add('text 1'); // index = 0
list.add('text 2'); // index = 1
list.add('text 3..etc'); //index = 2

// read data
var i:integer;

for i:=0 to 2 do begin
memo1.lines.add(list.strings[i]);
end;

Report
Re: Stringlist or not? Posted by heinrich13 on 30 May 2006 at 7:31 AM
: : I need to read information from something that are similar to a treeview (but it's not). Each level in the "tree" can have an unknown amount of sublevels and so can each sublevel and so on.
: :
: : Which is the best way to read and store this information? Can I use Stringlists and how will I do it? Any suggestions?
: :
: : The information I read will be saved to a textfile like this:
: :
: : Current context: A
: : A_1
: : A_2
: : A_3
: : Current context: A_1
: : A_1.1
: : A_1.2
: : A_1.3
: : .
: : .
: : etc
: :
: : A_1, A_2, A_1.1 etc are sublevels.
: :
: : /Heinrich
: :
: Use this to create a str list:
:
: public
: (global VARIABLE--)
: var List:Tstringlist;
:
: ----------------------------
:
: list := tstringlist.create;
:
: list.clear;
:
: list.add('text 1'); // index = 0
: list.add('text 2'); // index = 1
: list.add('text 3..etc'); //index = 2
:
: // read data
: var i:integer;
:
: for i:=0 to 2 do begin
: memo1.lines.add(list.strings[i]);
: end;
:
:

Thanks, but how will I keep track of all the sublevels and the sublevels to them and so on?
Report
Re: Stringlist or not? Posted by zibadian on 30 May 2006 at 10:49 AM
: : : I need to read information from something that are similar to a treeview (but it's not). Each level in the "tree" can have an unknown amount of sublevels and so can each sublevel and so on.
: : :
: : : Which is the best way to read and store this information? Can I use Stringlists and how will I do it? Any suggestions?
: : :
: : : The information I read will be saved to a textfile like this:
: : :
: : : Current context: A
: : : A_1
: : : A_2
: : : A_3
: : : Current context: A_1
: : : A_1.1
: : : A_1.2
: : : A_1.3
: : : .
: : : .
: : : etc
: : :
: : : A_1, A_2, A_1.1 etc are sublevels.
: : :
: : : /Heinrich
: : :
: : Use this to create a str list:
: :
: : public
: : (global VARIABLE--)
: : var List:Tstringlist;
: :
: : ----------------------------
: :
: : list := tstringlist.create;
: :
: : list.clear;
: :
: : list.add('text 1'); // index = 0
: : list.add('text 2'); // index = 1
: : list.add('text 3..etc'); //index = 2
: :
: : // read data
: : var i:integer;
: :
: : for i:=0 to 2 do begin
: : memo1.lines.add(list.strings[i]);
: : end;
: :
: :
:
: Thanks, but how will I keep track of all the sublevels and the sublevels to them and so on?
:
It is possible to add objects to stringlist items. I would suggest something like this:
  List.AddObject('Item 1', TStringList.Create);
    // Create an item and include a sublist
  TStringList(List.Objects[0]).AddObject('Item 1.1', TStringList.Create));
    // Create an item in the first sublist and add a subsublist

To get a certain string you need to run a code like this:
  s := TStringList(List.Objects[0]).Strings[0];
    // s = now 'Item 1.1'

It is important to type-cast the individual objects, otherwise you cannot access the various properties.
Report
Re: Stringlist or not? Posted by heinrich13 on 30 May 2006 at 11:15 PM
: : : : I need to read information from something that are similar to a treeview (but it's not). Each level in the "tree" can have an unknown amount of sublevels and so can each sublevel and so on.
: : : :
: : : : Which is the best way to read and store this information? Can I use Stringlists and how will I do it? Any suggestions?
: : : :
: : : : The information I read will be saved to a textfile like this:
: : : :
: : : : Current context: A
: : : : A_1
: : : : A_2
: : : : A_3
: : : : Current context: A_1
: : : : A_1.1
: : : : A_1.2
: : : : A_1.3
: : : : .
: : : : .
: : : : etc
: : : :
: : : : A_1, A_2, A_1.1 etc are sublevels.
: : : :
: : : : /Heinrich
: : : :
: : : Use this to create a str list:
: : :
: : : public
: : : (global VARIABLE--)
: : : var List:Tstringlist;
: : :
: : : ----------------------------
: : :
: : : list := tstringlist.create;
: : :
: : : list.clear;
: : :
: : : list.add('text 1'); // index = 0
: : : list.add('text 2'); // index = 1
: : : list.add('text 3..etc'); //index = 2
: : :
: : : // read data
: : : var i:integer;
: : :
: : : for i:=0 to 2 do begin
: : : memo1.lines.add(list.strings[i]);
: : : end;
: : :
: : :
: :
: : Thanks, but how will I keep track of all the sublevels and the sublevels to them and so on?
: :
: It is possible to add objects to stringlist items. I would suggest something like this:
:
:   List.AddObject('Item 1', TStringList.Create);
:     // Create an item and include a sublist
:   TStringList(List.Objects[0]).AddObject('Item 1.1', TStringList.Create));
:     // Create an item in the first sublist and add a subsublist
: 

: To get a certain string you need to run a code like this:
:
:   s := TStringList(List.Objects[0]).Strings[0];
:     // s = now 'Item 1.1'
: 

: It is important to type-cast the individual objects, otherwise you cannot access the various properties.
:

Thank you, I will try this out.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.