Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Stringlist or not?

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

Comments

  • porodoroporodoro Posts: 230Member
    : 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;

  • heinrich13heinrich13 Posts: 3Member
    : : 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?
  • zibadianzibadian Posts: 6,349Member
    : : : 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:
    [code]
    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
    [/code]
    To get a certain string you need to run a code like this:
    [code]
    s := TStringList(List.Objects[0]).Strings[0];
    // s = now 'Item 1.1'
    [/code]
    It is important to type-cast the individual objects, otherwise you cannot access the various properties.
  • heinrich13heinrich13 Posts: 3Member
    : : : : 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:
    : [code]
    : 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
    : [/code]
    : To get a certain string you need to run a code like this:
    : [code]
    : s := TStringList(List.Objects[0]).Strings[0];
    : // s = now 'Item 1.1'
    : [/code]
    : It is important to type-cast the individual objects, otherwise you cannot access the various properties.
    :

    Thank you, I will try this out.
Sign In or Register to comment.