[Lazarus] TStringList vs TTextStrings vs whatever

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Mar 27 22:40:34 CET 2008


On Thu, 27 Mar 2008 20:11:31 +0200
"Graeme Geldenhuys" <graemeg.lists at gmail.com> wrote:

> Hi,
> 
> Andrew Haines started implementing a new TStrings descendant for use
> as internal storage for fpGUI's Memo component (optimized for speed).
> This got me curious as to why many developers don't use TStringList
> itself.  Look around and then also at LCL's TMemo, I noticed Mattias
> seems to have had the same idea, implementing his own descendant class
> called TTextStrings.  Abstract from the unit (textstrings.pas) header:
> 
> ----------------------
> TTextStrings is a TStrings descendant that is optimized for handling
> the complete text as whole (instead of as line by line as in
> TStringList).
> ----------------------
> 
> It seems a lot of developers are not happy with TStringList.  What's
> the actual downside of using TStringList for internal storage in a
> text component like Memo or ListBox?  Performance?  If so, why don't
> we _fix_ the implementation in TStringList itself, instead of
> everybody creating their own descendants?
> 
> Yes, LCL's TMemo does currently use TStringList for internal storage,
> but clearly Mattias did at some stage think of using TextStrings as
> the commented code shows.

I'm happy with TStringList. It should stay as an array of strings.
But in some cases you want a text as single string and only
occasionally access its lines. It's just a matter of optimization. You
can not optimize for both.

About TMemo:
Nowadays every widgetset uses its own optimized TStrings descendant,
so no need for TTextStrings.

But a TTextStrings is needed in some cases.

Mattias



More information about the Lazarus mailing list