0

I'm attempting to add a constant list of values to a TStringList.

My first thought was to use the DelimitedText attribute, but it's broken in 7 (space is always a delimiter), plus, it overwrites whatever is already in the TStringList.

I looked at the AddStrings, but I'd like to avoid instantiating another object if I can help it.

I could just iterate over a constant array of string, but it seems like there should be an easier way.

Remko
  • 7,214
  • 2
  • 32
  • 52
Morgan Thrapp
  • 9,748
  • 3
  • 46
  • 67
  • I'm not aware of anything easier (or else) than iteration (assuming we are talking about a constant array of strings). Recent versions has an overload for adding `TArray`. – TLama Mar 31 '15 at 17:51
  • @TLama Alright, that's what I was afraid of. Thanks. – Morgan Thrapp Mar 31 '15 at 17:56
  • 3
    Why ? It's not that bad. Even the recent version of Delphi must iterate a passed `TArray`. You just lock the string list with a `BeginUpdate`, `EndUpdate` block and iterate the array adding its elements. It's a very short piece of quite efficient code. – TLama Mar 31 '15 at 18:01
  • Its seems like there should be an easier way and there is an easier way are not the same thing. Sometimes there is just a way. – Toby Allen Apr 03 '15 at 08:28

0 Answers0