So, I want to sort array of strings by length (longer strings goes first) and if length is the same, then sort alphabetically. This is what is got so far:
uses
System.Generics.Defaults
, System.Types
, System.Generics.Collections
;
procedure TForm2.FormCreate(Sender: TObject);
var
_SortMe: TStringDynArray;
begin
_SortMe := TStringDynArray.Create('abc', 'zwq', 'Long', 'longer');
TArray.Sort<string>(_SortMe, TDelegatedComparer<string>.Construct(
function(const Left, Right: string): Integer
begin
Result := CompareText(Left, Right);
end));
end;
Expected result: longer, Long, abc, zwq