The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,152 other subscribers

delphi – Why variables are declared as TStrings and created as TStringList? – Stack Overflow

Posted by jpluimers on 2019/07/24

Blast from the past: [WayBackdelphi – Why variables are declared as TStrings and created as TStringList? – Stack Overflow


Why variables are declared as TStrings and created as TStringList?


Because that way you could put another TStrings descendant in the SL variable (I’d probably call that Strings, not SL).

In your case, that is moot, since the logic around SL contains the creation of a TStringList and no external assignment or parameter parsing.

But if you ever split the logic away from the assignment, then you could benefit from using any TStrings descendant.

For instance, a TMemoy.LinesTListBox.ItemsTComboBox.Items, etc.
From the outside it looks like they are TStrings, but internally they do not use a TStringList but their own descendant.

A few examples of classes that descend from TStrings:

     TXPEditorStrings = class(TStrings)
       TListBoxStrings = class(TStrings)
     TMemoLines = class(TStrings)
     TStringList = class(TStrings)
     TTabStrings = class(TStrings)
     TTreeStrings = class(TStrings)
     TRichEditStrings = class(TStrings)
     TPageAccess = class(TStrings)
     THeaderStrings = class(TStrings)
     TStringGridStrings = class(TStrings)
     TStringSparseList = class(TStrings)
     TOutlineStrings = class(TStrings)
     TCustomComboBoxStrings = class(TStrings)
     TMemoStrings = class(TStrings)
     TListBoxStrings = class(TStrings)
     TTabPageAccess = class(TStrings)


One Response to “delphi – Why variables are declared as TStrings and created as TStringList? – Stack Overflow”

  1. Arnaud Bouchez said

    Note that this is a nice example of the Liskov substition principle. See

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: