Blast from the past: [WayBack] delphi – Why variables are declared as TStrings and created as TStringList? – Stack Overflow
Q
Why variables are declared as
TStringsand created asTStringList?A
Because that way you could put another
TStringsdescendant in theSLvariable (I’d probably call thatStrings, notSL).In your case, that is moot, since the logic around
SLcontains the creation of aTStringListand no external assignment or parameter parsing.But if you ever split the logic away from the assignment, then you could benefit from using any
TStringsdescendant.For instance, a
TMemoy.Lines,TListBox.Items,TComboBox.Items, etc.
From the outside it looks like they areTStrings, but internally they do not use aTStringListbut their own descendant.A few examples of classes that descend from
TStrings:source\DUnit\Contrib\DUnitWizard\Source\DelphiExperts\Common\XP_OTAEditorUtils.pas: TXPEditorStrings = class(TStrings) source\fmx\FMX.ListBox.pas: TListBoxStrings = class(TStrings) source\fmx\FMX.Memo.pas: TMemoLines = class(TStrings) source\rtl\common\System.Classes.pas: TStringList = class(TStrings) source\vcl\Vcl.ComCtrls.pas: TTabStrings = class(TStrings) TTreeStrings = class(TStrings) TRichEditStrings = class(TStrings) source\vcl\Vcl.ExtCtrls.pas: TPageAccess = class(TStrings) THeaderStrings = class(TStrings) source\vcl\Vcl.Grids.pas: TStringGridStrings = class(TStrings) TStringSparseList = class(TStrings) source\vcl\Vcl.Outline.pas: TOutlineStrings = class(TStrings) source\vcl\Vcl.StdCtrls.pas: TCustomComboBoxStrings = class(TStrings) TMemoStrings = class(TStrings) TListBoxStrings = class(TStrings) source\vcl\Vcl.TabNotBk.pas: TTabPageAccess = class(TStrings)
–jeroen





