if Result = 0 then
begin
if ARecord1.String5 < ARecord2.string5 then
begin
Result := -1
end else
// FELD 2
begin
if ARecord1.Field2 > Arecord2.Field2 then
begin
Result := 1;
end else
begin
if ARecord1.Field2 < ARecord2.Field2 then
begin
Result := -1
end else
Looking at your code I see you're implementing a Quick Sort and an external compare function already. So right from the start you're on the track that myself and several others have suggested. Oops, apologies for missing that in your first post.
In order to use BeniBela's code you just to make small changes to your Compare function (change paramters etc).
But now I've looked at your code closely, I think there may be errors in your Compare function (which is why I highlighted it above). Your compare function is going to result in a dataset that would not look sorted to me. You're falling from one case to the next
if one string is not less than the other. For traditional sort implementations you usually
only compare subsequent strings when the previous strings are identical. You do this for Field2, but not for Field5
Have a look at @soerensen3's implementation for an example.
Result:= CompareStringField( Field1, AObj.Field1 );
if ( Result = 0 ) then
Result:= CompareStringField( Field2, AObj.Field2 );
if ( Result = 0 ) then
Result:= CompareStringField( Field3, AObj.Field3 );
if ( Result = 0 ) then
Result:= CompareIntField( Field4, AObj.Field4 );
end;[/code]
I think if you refactor your Compare function so it's got same general shape as @soerensen3's, you'll find you've been on a good track all along.
And I don't think you'll need the internal CompareStringField. Freepascal already comes with string comparison routines.
https://www.freepascal.org/docs-html/rtl/sysutils/comparestr.html (see also the
See Also's :-) )