So you first want to sort on the second column, and then on the fourth column. Then you need TStringList.CustomSort
.
From the help about the TStringListSortCompare
function type:
Index1 and Index2 are indexes of the items in List to compare. The callback returns:
- a value less than 0 if the string identified by Index1 comes before the string identified by Index2
- 0 if the two strings are equivalent
- a value greater than 0 if the string with Index1 comes after the string identified by Index2.
So if you first compare on the second column, and when equal, proceed comparing on the fourth. Assuming all text is capitalized, all strings are equal in size and with identical syntax, then this should work:
function CompareItems(List: TStringList; Index1, Index2: Integer): Integer;
begin
Result := CompareStr(Copy(List[Index1], 25, 6), Copy(List[Index2], 25, 6));
if Result = 0 then
Result := CompareStr(Copy(List[Index1], 39, 7), Copy(List[Index2], 39, 7));
end;
Usage:
List.CustomSort(CompareItems);