what are the differences between TStrings and TStringList ?
TStrings is an abstract base class.
TStringList is a concrete descendant of
TStrings. There are other descendants available, such as used by the
TMemo.Lines property, the
TListBox.Items property, etc.
in my Delphi Times, I had created:
...
But the point, I would know: why TStrings, and not TStringList in variable definition section ?
In your particular example, it make no any difference whatsoever, as there is only 1 descendant involved, and everything is local to the procedure. So use whichever type you want for the variable declaration.
But, in more complex situations, where multiple list objects/descendants are involved, or the variable is a function parameter, etc, then it makes more sense to declare the variable/parameter as
TStrings to offer yourself flexibility in which object/descendant can be used, for example:
procedure AddToList(AStrings: TStrings);
begin
AStrings.Add('foo bar');
end;
procedure DoSomethingWithMemo;
begin
...
AddToList(Memo1.Lines);
...
end;
procedure DoSomethingWithListBox;
begin
...
AddToList(ListBox1.Items);
...
end;
procedure DoSomethingWithStringList;
var
slList: TStringList;
begin
...
slList := TStringList.Create;
try
...
AddToList(slList);
...
finally
slList.Free;
end;
...
end;
procedure DoSomethingWithAlternateLists;
var
listToAddTo: TStrings;
slList: TStringList;
begin
...
if SomeCondition then
listToAddTo := Memo1.Lines
else if SomeOtherCondition then
listToAddTo := ListBox1.Items
else begin
slList := TStringList.Create;
listToAddTo := slList;
end;
try
...
AddToList(listToAddTo);
...
finally
slList.Free;
end;
...
end;