First of all I question whether or not you have chosen the correct type to represent your data structure. You say your type is
array of array of string
But it looks like the inner array always has exactly two elements, the first an integer, and the second a string. In that case the inner array should be replaced with a record.
type
TMyElement = record
ID: Integer;
Name: string;
end;
TMyArray = array of TMyElement;
And now you just have a one dimensional array. I assume you have no difficulty sorting one of those.
But suppose that you really did need a multi-dimensional array. Suppose that the array was ragged, i.e. that different inner arrays had different lengths. You can still view that array as a one-dimensional array. Declare it like this:
TStringArray = array of string;
TMyArray = array of TStringArray;
Now you can sort TMyArray
just as if it were a one-dimensional array.
Note that I needed to declare a type for the inner array. The reason being that the sort function needs to be able to compare and exchange elements of the outer array. So you'll need functions to do that. And you need to define a type to achieve that. For example, your exchange function might look like this:
procedure Exchange(Index1, Index2: Integer);
var
temp: TStringArray;
begin
temp := MyArray[Index1];
MyArray[Index1] := MyArray[Index2];
MyArray[Index2] := temp;
end;
Without defining TStringArray
, this would not be possible. That's because of the rather stringent assignment compatibility rules for dynamic arrays.
You can extend to as many dimensions as you like:
TString2DArray = array of TStringArray;
TMyArray = array of TString2DArray;
Again, you can use your standard array sort to sort this three dimensional version of TMyArray
.