function QCompare(Item1, Item2:
string;
const SortByProvider: boolean): integer;
var
Provider1, Provider2, Name1, Name2 :
string;
begin
Item1:= AnsiLowerCase(Trim(Item1));
Item2:= AnsiLowerCase(Trim(Item2));
Result:= 0;
if not SortByProvider
then
begin
if Item1 > Item2
then
Result:= 1
else
if Item1 < Item2
then
Result:= -1;
end
else
begin
Provider1:= GetDomainPart(Item1);
Provider2:= GetDomainPart(Item2);
Name1:= GetNamePart(Item1);
Name2:= GetNamePart(Item2);
if Provider1 > Provider2
then
Result:= 1
else
if Provider1 < Provider2
then
Result:= -1
else
if Name1 > Name2
then
Result:= 1
else
if Name1 < Name2
then
Result:= -1;
end;
end;
procedure QuickSort
(
const Strings: TStrings; L, R: integer;
const QCompare: TQCompare;
const SortByProvider: boolean);
var
I, J, K: integer;
P:
string;
begin
repeat
I:= L;
J:= R;
K:= (L + R)
shr 1;
P:= Strings[K];
repeat
while QCompare(Strings[I], P, SortByProvider) < 0
do Inc(I);
while QCompare(Strings[J], P, SortByProvider) > 0
do Dec(J);
if I <= J
then // **********************************************************************
begin
Strings.Exchange(I, J);
Inc(I);
Dec(J);
end;
until I > J;
if L < J
then QuickSort(Strings, L, J, QCompare, SortByProvider);
L:= I;
until I >= R;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
SL: TStringList;
begin
SL:= TStringList.Create;
SL.Assign(Memo1.Lines);
SL.BeginUpDate;
QuickSort(SL, 0, SL.Count-1, @QCompare, true);
SL.EndUpDate;
Memo1.Lines.Assign(SL);
SL.Free;
end;