Erro ao carregar todos os arquivos...

Delphi

20/10/2004

Estou tentando carregar varios arquivos TXT, só que na procedure abaixo, toda vez que chamo ela falta 1 arquivo.
O que há de errado com ela?

procedure TCarregaDadosForm.CarregaBTClick(Sender: TObject);
var
sr: TSearchRec;
FileAttrs: Integer;
FileSpec: String;
Letra: String;
i: Integer;
begin
CarregaBT.Enabled := False;
Letra := ´´;
FilesCLB.Items.Clear;
FileAttrs := faArchive;
FileSpec := SCCardPathED.Text + ´\´+´*.TXT´;
i := 0;
if FindFirst(FileSpec, FileAttrs, sr) = 0 then
begin
i := 0;
while FindNext(sr) = 0 do
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
if i >= NMaxFiles then
begin
MessageDlg(´Tela limitada a ´+IntToStr(NMaxFiles)+´ arquivo(s)´, mtInformation,[mbOk], 0);
break;
end;
FilesCLB.Items.Add(sr.Name);
i := i + 1;
end;
end;
FindClose(sr);
end;
if i = 0 then
begin
MessageDlg(´Não há arquivos para processar: ´ + FileSpec , mtInformation,[mbOk], 0);
end;
CarregaBT.Enabled := True;
end;


Wgm8

Wgm8

Curtidas 0

Respostas

Ipc$

Ipc$

20/10/2004

if FindFirst(FileSpec, FileAttrs, sr) = 0 then begin i := 0; while FindNext(sr) = 0 do

FindFirst já retorna o primeiro arquivo e vc o perde dando o FindNext.


GOSTEI 0
Wgm8

Wgm8

20/10/2004

Como poderia corrigir?

[quote:b963427539=´IPC$´]
if FindFirst(FileSpec, FileAttrs, sr) = 0 then begin i := 0; while FindNext(sr) = 0 do

FindFirst já retorna o primeiro arquivo e vc o perde dando o FindNext.[/quote:b963427539]


GOSTEI 0
Ipc$

Ipc$

20/10/2004

Troque:
while FindNext(sr) = 0 do
Por:
While 0=0 do

Antes do end deste While coloque:
if FindNext(sr) 0 then
Break;


GOSTEI 0
Wgm8

Wgm8

20/10/2004

:)


GOSTEI 0
POSTAR