TStringList.Exchange

From Soldat Community Wiki
Revision as of 12:42, 24 August 2013 by Mighty (talk | contribs) (new page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
procedure Exchange(Index1, Index2: Integer)
 Index1: Index no. 1
 Index2: Index no. 2

Description

Exchange will exchange two items in the list.
It does not check whether the list is sorted or not; if Exchange is called on a sorted list and the strings are not identical, the sort order of the list will be destroyed.

Example

var
  s: TStringList;

begin
  s := File.CreateStringList();
  s.Append('a');
  s.Append('b');
  s.Append('c');
  
  s.Exchange(0,2);
  
  WriteLn(s.CommaText);
  // c,b,a
  
  s.Free;
end.