Hola ZayDun.
No se que te puede estar pasando... ¿ Será la versión de Delphi ? he visto que hay muchas diferencias entre Delphi 7 y EX4.
Esta es la prueba con el código anterior que en Delphi 7 funciona sin problemas:
Código Delphi
[-]
...
implementation
procedure SortByUserName(TS: TStrings);
function CompareNom(TS: TStrings; const i1, i2: Integer): Integer;
begin
Result:= CompareText(Copy(TS[i1],4,MaxInt)+Copy(TS[i1],1,3),
Copy(TS[i2],4,MaxInt)+Copy(TS[i2],1,3));
end;
var
SL: TStringList;
begin
SL:= TStringList.Create;
try
SL.Assign(TS);
SL.CustomSort(@CompareNom);
TS.Assign(SL);
finally
SL.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
Randomize;
for i:= 1 to 22 do
ListBox1.Items.Add(Format('%.3d Usuario%s',[i,Chr(65+Random(26))]));
ListBox2.Items.Assign(ListBox1.Items);
SortByUserName(ListBox2.Items);
end;
Resultado:
Saludos