I bring some bank records with a specific order and play into a vector of type record
". Then I need to add more items to that vector by keeping the initial sort. Since the ordering is done in SQL
the records that are added then 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 it does in ORDER BY
of SQL
having the option to sort by multiple fields. I use mORMot
too but I have not found anything in the documentation that does this.
I was able to find an example that does the ordering, it works perfectly, but it only does for a field. Here is the code:
Record example:
TRegistro = record
CODIGO: Integer;
NOME: string;
DATA: TDateTime;
CIDADE: string;
end;
TRegistros = array of TRegistro;
Sorting:
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;