TStringList is the most commonly used types of list. For example, items of combo box, lines in a memo, names of rows, columns and any list of strings. TStringList is derived from TStrings and it implements the abstract methods of TStrings and introduces some properties, events and methods like sorting, prohibiting duplicate strings in the sorted list etc.
Safest way of using TStingList is, create, use and destroy. Steps are
Create the string list object
Use the list within try...finally block.
Free the string-list object
Safest way of using TStingList is, create, use and destroy. Steps are
Create the string list object
Use the list within try...finally block.
Free the string-list object
procedure TForm1.Button1Click(Sender: TObject);
var
tempStringList:TStringList; {Declare the sting list}
i :Integer;
begin
tempStringList := TStringList.Create; {Create the string list}
try {Use the list within try-finally block}
tempStringList.Add('Cindrella');
tempStringList.Add('Rapunzel');
tempStringList.Add('Pocahontas');
for i:=0 to tempStringList.Count - 1 do
ShowMessage(tempStringList[i]);
finally {Free the list when it is not required}
tempStringList.Free;
end;
end;
- 3786 reads