1
I bring some bank records with a specific sorting and play into a vector of the type record
. Then I need to add more items in this array keeping the initial sort. How the sort is done in the SQL
the records that are added later end up going to the end of the vector.
I want to know if there is any way to reorder this vector in the same way as in ORDER BY
of SQL
having the option to sort by several fields. I use mORMot
but I haven’t found anything in the documentation to do that either.
I managed to find an example that does the ordering, it works perfectly, but only does for a field. Follow the code:
Record example:
TRegistro = record
CODIGO: Integer;
NOME: string;
DATA: TDateTime;
CIDADE: string;
end;
TRegistros = array of TRegistro;
Ordination:
procedure SortArray(var Matriz: TRegistros);
var
Posicao1, Posicao2: Integer;
Temporario: TRegistro; // Variável Temporária para Alternar Valores
begin
for Posicao1 := 0 to Length(Matriz) - 1 do
begin
for Posicao2 := 0 to (Length(Matriz) - 2) do
begin
if (Matriz[Posicao2].CODIGO > Matriz[Posicao2 + 1].CODIGO ) then // Ordem Crescente
begin
Temporario := Matriz[Posicao2];
Matriz[Posicao2] := Matriz[Posicao2 + 1];
Matriz[Posicao2 + 1] := Temporario;
end;
end;
end;
end;
So, only this one only does the ordering for one field. I needed something similar to
ORDER BY
ofSQL
, sort through several fields.– Wendel Rodrigues