Le arquivo txt
Preciso ler um arquivo texto do fim para o começo, pelo que vi no Delphi não tem nenhuma função que possa mover pro registro anterior.
Existe alguma forma de contornar isso ?
vlwe
Existe alguma forma de contornar isso ?
vlwe
Eduardo Rocha
Curtidas 0
Respostas
Bruno Leandro
20/04/2012
voce pode usar o tstringlist e usar o um for de count -1 até 0
GOSTEI 0
Joel Rodrigues
20/04/2012
Bem, vejamos, no comando FOR do Delphi, você pode substituir o TO por DOWNTO. Por exemplo, seguindo a dica acima, você pode carregar o arquivo em um TStringList e ler cada linha da seguinte forma:
Boa sorte.
for i := Pred(lista.Strings.Count) downto 0 do //faça algo
Boa sorte.
GOSTEI 0
Bruno Leandro
20/04/2012
procedure lerTxtInvertido;
var
stringlist: tstringlist;
i : integer;
sLinha: string;
begin
stringlist := tstringlist.create;
stringlist.LoadFromFile(C:\teste.txt);
for I := stringlist.Count - 1 downto 0 do
begin
sLinha := stringlist[i];
ShowMessage([Linha: + inttostr(i) + ] + sLinha);
end;
end;
var
stringlist: tstringlist;
i : integer;
sLinha: string;
begin
stringlist := tstringlist.create;
stringlist.LoadFromFile(C:\teste.txt);
for I := stringlist.Count - 1 downto 0 do
begin
sLinha := stringlist[i];
ShowMessage([Linha: + inttostr(i) + ] + sLinha);
end;
end;
GOSTEI 0
Joel Rodrigues
20/04/2012
Isso, isso, isso.
GOSTEI 0
Eduardo Rocha
20/04/2012
valeu galera, perfeito !
GOSTEI 0