var
List: TStringList;
i:
Integer
;
begin
List := TStringList
.
Create;
List
.
Add(
'Strings1'
);
List
.
Add(
'Strings2'
);
List
.
Exchange(
0
,
1
);
List
.
Insert(
0
,
'Strings3'
);
i := List
.
IndexOf(
'Strings1'
);
List
.
Sort;
List
.
Sorted :=
True
;
List
.
Count;
List
.
Text;
List
.
Delete(
0
);
List
.
LoadFromFile(
'c: mp.txt'
);
List
.
SaveToFile(
'c: mp.txt'
);
List
.
Clear;
List
.
Free;
end
;
var
List: TStringList;
begin
List := TStringList
.
Create;
List
.
CommaText :=
'aaa,bbb,ccc,ddd'
;
ShowMessage(IntToStr(List
.
Count));
ShowMessage(List[
0
]);
List
.
Free;
end
;
var
List: TStringList;
begin
List := TStringList
.
Create;
List
.
Delimiter :=
'|'
;
List
.
DelimitedText :=
'aaa|bbb|ccc|ddd'
;
ShowMessage(IntToStr(List
.
Count));
ShowMessage(List[
0
]);
List
.
Free;
end
;
var
List: TStringList;
begin
List := TStringList
.
Create;
List
.
Add(
'aaa=111'
);
List
.
Add(
'bbb=222'
);
List
.
Add(
'ccc=333'
);
List
.
Add(
'ddd=444'
);
ShowMessage(List
.
Names[
1
]);
ShowMessage(List
.
ValueFromIndex[
1
]);
ShowMessage(List
.
Values[
'bbb'
]);
List
.
ValueFromIndex[
1
] :=
'2'
;
ShowMessage(List[
1
]);
List
.
Values[
'bbb'
] :=
'22'
;
ShowMessage(List[
1
]);
List
.
Free;
end
;
var
List: TStringList;
begin
List := TStringList
.
Create;
List
.
Add(
'aaa'
);
List
.
Sorted :=
True
;
List
.
Duplicates := dupIgnore;
List
.
Add(
'aaa'
);
ShowMessage(List
.
Text);
List
.
Free;
end
;
function
DescCompareStrings(List: TStringList; Index1, Index2:
Integer
):
Integer
;
begin
Result := -AnsiCompareText(List[Index1], List[Index2]);
end
;
procedure
TForm1
.
Button1Click(Sender: TObject);
var
List: TStringList;
begin
List := TStringList
.
Create;
List
.
Add(
'bbb'
);
List
.
Add(
'ccc'
);
List
.
Add(
'aaa'
);
ShowMessage(List
.
Text);
List
.
Sort;
ShowMessage(List
.
Text);
List
.
CustomSort(DescCompareStrings);
ShowMessage(List
.
Text);
List
.
Sorted :=
True
;
List
.
Add(
'999'
);
List
.
Add(
'000'
);
List
.
Add(
'zzz'
);
ShowMessage(List
.
Text);
end
;