0

After failing to sort my TStringList file using TStringList.Sort because numbers won't sort properly, (instead of doing 1,4,12,32 its doing 1,12,32,4 because the numbers are considered text on a TStringList), i've tried to do it a number of other ways and i can't seen to do it.

here is my code:

var
  Database, DBResultado, DBAux: TStringList;
  Aux,Aux2: string;
  i, Num, Reserva: integer;
begin
  Memo.Clear;
  Database := TStringList.Create;
  DBResultado := TStringList.Create;
  DBAux := TStringList.Create;
  Database.LoadFromFile('DATABASEPATH');


  for I := 0 to Database.Count - 1 do
  begin
    Aux := StringReplace(Database[i], 'Cliente', '', [rfReplaceAll]);
    Aux := StringReplace(Aux, ';', '', [rfReplaceAll]);
    DBResultado.Add(FormatFloat('00000', StrToInt(Aux)));



  end;
    DBResultado.Sort;
    Memo.Lines.Add(DBResultado.Text);

    for i := 0 to Database.Count - 1 do
    begin
      Aux2 := IntToStr(StrToInt(DBResultado[i]));
      DBAux[i] := Aux2;
    end;
    Memo.clear;
    Memo.Lines.Add(DBAux.Text);

    DBResultado.SaveToFile('DATABASEPATH');
end;

The code gets a Database that is just a list like this:

Client1;
Client65;
Client13;
etc...

and this database is linked to files with the same name that have client data

i managed to get down to numbers and to even sort them, but now i don't know how to move them back to the database.

There must be a better way of doing this.

Trying to change them to numbers and back isn't working and i have no idea what i'm doing tbh. i only want the DB to look like its in order

Client1;
Client2;
Client13,
Client16;
etc...

also i have tried adding the string back to the original tstringlist but its not working, something about compatibility.

  • This one...? Andreas, was there supposed to be a link in your comment ? – Andrei Zx Oct 26 '22 at 19:13
  • 1
    The link was removed from the comments and added to the duplicate list in the colored box at the top of the page. It's at the very top of your question now, just below the title. – Ken White Oct 27 '22 at 00:20

0 Answers0