Processando a Leitura de Arquivo TXT
19/02/2003
0
Pessoal Estou lendo um arquivo retorno a rotina esta abaixo mas eu acrecentei no meu formulario um Gauge1 para poder saber o quanto ai esta faltando para terminal a leitura como e aonde eu debo colocar o procedimento eu que no inicio cola
Gauge1.Progress := 0;
Gauge1.Maxvalue := {aqui que nao sei acresentar o total de linhas que possui o meu registro TXT}
Procedure LeArquivo;
AssignFile(fArquivo,´Retorno.txt´);
{$i-}
Reset(fArquivo);
{$i+}
If (IOResult <> 0) then
begin
Application.MessageBox(´Arquivo não Encontrado´,Erro´,MB_OK+MB_ICONSTOP);
end
else
begin
while not Eoln(fArquivo) do
begin
Readln(fArquivo,fReg);
cNomeEmpresa := Copy(fReg,1,40); // Tamanho 40
Gauge1.Progress := Gauge1.Progress + 1; {acho que e aqui}
end;
end;
Gauge1.Progress := 0;
Gauge1.Maxvalue := {aqui que nao sei acresentar o total de linhas que possui o meu registro TXT}
Procedure LeArquivo;
AssignFile(fArquivo,´Retorno.txt´);
{$i-}
Reset(fArquivo);
{$i+}
If (IOResult <> 0) then
begin
Application.MessageBox(´Arquivo não Encontrado´,Erro´,MB_OK+MB_ICONSTOP);
end
else
begin
while not Eoln(fArquivo) do
begin
Readln(fArquivo,fReg);
cNomeEmpresa := Copy(fReg,1,40); // Tamanho 40
Gauge1.Progress := Gauge1.Progress + 1; {acho que e aqui}
end;
end;
Silvio
Curtir tópico
+ 0
Responder
Posts
19/02/2003
Carnette
partindo do principio que cada registro tem 40 bytes podemos fazer o seguinte
iFileLength := FileSeek(iFileHandle,0,2)/40
AssignFile(fArquivo,´Retorno.txt´);
{$i-}
Reset(fArquivo);
{$i+}
If (IOResult <> 0) then
begin
Application.MessageBox(´Arquivo não Encontrado´,Erro´,MB_OK+MB_ICONSTOP);
end
else
begin
// é aqui o gauge
Gauge1.Maxvalue := Trunc( FileSeek(iArquivo,0,2)/40)
//
while not Eoln(fArquivo) do
begin
Readln(fArquivo,fReg);
cNomeEmpresa := Copy(fReg,1,40); // Tamanho 40
Gauge1.Progress := Gauge1.Progress + 1; {acho que e aqui}
end;
end;
iFileLength := FileSeek(iFileHandle,0,2)/40
AssignFile(fArquivo,´Retorno.txt´);
{$i-}
Reset(fArquivo);
{$i+}
If (IOResult <> 0) then
begin
Application.MessageBox(´Arquivo não Encontrado´,Erro´,MB_OK+MB_ICONSTOP);
end
else
begin
// é aqui o gauge
Gauge1.Maxvalue := Trunc( FileSeek(iArquivo,0,2)/40)
//
while not Eoln(fArquivo) do
begin
Readln(fArquivo,fReg);
cNomeEmpresa := Copy(fReg,1,40); // Tamanho 40
Gauge1.Progress := Gauge1.Progress + 1; {acho que e aqui}
end;
end;
Responder
19/02/2003
Anonymous
Pessoal Estou lendo um arquivo retorno a rotina esta abaixo mas eu acrecentei no meu formulario um Gauge1 para poder saber o quanto ai esta faltando para terminal a leitura como e aonde eu debo colocar o procedimento eu que no inicio cola
Gauge1.Progress := 0;
Gauge1.Maxvalue := {aqui que nao sei acresentar o total de linhas que possui o meu registro TXT}
Procedure LeArquivo;
AssignFile(fArquivo,´Retorno.txt´);
{$i-}
Reset(fArquivo);
{$i+}
If (IOResult <> 0) then
begin
Application.MessageBox(´Arquivo não Encontrado´,Erro´,MB_OK+MB_ICONSTOP);
end
else
begin
while not Eoln(fArquivo) do
begin
Readln(fArquivo,fReg);
cNomeEmpresa := Copy(fReg,1,40); // Tamanho 40
Gauge1.Progress := Gauge1.Progress + 1; {acho que e aqui}
end;
end;
Caro Silvio,
O código abaixo considera um aquivo do tipo ´flatfile´ (texto) de tamanho fixo e a partir da leitura do primeiro registro, obtem o comprimento do mesmo e calcula a quantidade de linhas.
Atenciosamente,
[]´s
Aroldo Zanela
Form1.OnAlgumEvento; Var FlatFile: TextFile; LineData: String; LineLength: Integer; Line: Integer; FileHandle: Integer; FileName: String; FileLength: Integer; iLineFeed: Integer; begin Gauge1.Progress:= 0;// Inicializa re.Lines.Clear; // Solte um RichEdit e altere o nome para re FileName:= ´C:\TEMP\ARQUIVO.TXT´;// Nome do arquivo FileHandle:= FileOpen(FileName,2);// Obtem o handle FileLength:= Trunc(FileSeek(FileHandle,0,2)); // Obtem o tamanho FileClose(FileHandle);// Solta o handle AssignFile(FlatFile,FileName);// Associa o objeto ao nome Reset(FlatFile);// Abre para leitura ReadLn(FlatFile,LineData);// Lê a primeira linha re.Lines.Add(LineData); iLineFeed:= 1; // 1 - Unix ou 2 - Windows/DOS Line:= 1;// Numero da linha (Recno) LineLength:= Length(LineData)+iLineFeed;// Obtem o tamanho da linha/registro + CR LF Gauge1.MaxValue:= FileLength div LineLength; while not eof(FlatFile) do begin ReadLn(FlatFile,LineData); Inc(Line); Gauge1.Progress:= ((Line*100) div Gauge1.MaxValue); re.Lines.Add(LineData); end; CloseFile(FlatFile); end;
Responder
Clique aqui para fazer login e interagir na Comunidade :)