How to use Generic TList Class in Delphi?
How to use Generic TList Class in Delphi? TList generic class is used to store a list of various data type variables in Delphi. Below is the simple program to illustrate the concept of TList generic class in Delphi. var List: TList<Integer>; FoundIndex: Integer; begin { Create a new List. } List := TList<Integer>.Create; { Add a few values to the list. } List.AddRange([5, 1, 8, 2, 9, 14, 4, 5, 1]); writeln('Index of first 1 is ' + IntToStr(List.IndexOf(1))); writeln('Index of last 1 is ' + IntToStr(List.LastIndexOf(1))); writeln('Does List contains element 100? ' + BoolToStr(List.Contains(100))); { Add another element to the list. } List.Add(100); writeln('There are ' + IntToStr(List.Count) + ' elements in the list.'); { Remove the first occurrence of 1. } List.Remove(1); { Delete a few elements from position 0. } List.Delete(0); List.DeleteRange(0, 2); ...