Access lines of a TStringList

Jul 13, 2011 at 2:59pm
Hello all!

I have a question regarding Borland C++ Builder. I am writing a program that needs to access individual lines of a TStringList and turn each line into an AnsiString. Is there a method of either TStringList or AnsiString similar to getline() but for TStringLists? Or is there another method in some other class that allows one to do this?

Thanks in advance!
Jul 13, 2011 at 5:51pm
I figured out the problem (kind of a roundabout way though). For anyone that needs to know how to do this, I put the steps below:

1. Make a memo (if you need it to be invisible, then you can do that.)
2. Add strings to the TStringList of the memo (via anything. Typing, file import, etc.)
3. Use the code below to turn up the number of lines in the TStringList in integers:

Memo1->Lines->Count;

4. Access each individual line using this code:

Memo1->Lines->Strings[NUMBER OF LINE]

In which the Memo1 is the name of the memo and NUMBER OF LINE is the number of the string you are trying to access.
Jul 13, 2011 at 6:10pm
The memo is unnecessary, as you can access the lines the same way in the original string list (StringList->Strings[index]).
Jul 13, 2011 at 7:23pm
Okay, I think I tried that before, but I'll give it another go now that I understand it a little better. Thanks for the reply!

Edit: Yup, Athar you're correct, you don't need to use the memo.
Last edited on Jul 13, 2011 at 7:28pm
Topic archived. No new replies allowed.