GARANTIR DESCONTO

Fórum consulta e inclusão em um arquivo txt.. #181772

12/09/2003

0

bom dia pessoal estou com um erro com arquivo txt que é o seguinte..

tenho um edit que faço o seguinte.. digito um numero... ele verifica num arquivo txt se o veiculo é da empresa ou não... até ai tudo bem ele faz legal.... este é o código

procedure TForm1.Edit1Exit(Sender: TObject);

var TEXT: textfile;
VALOR,PLACA: string;
begin
if Fileexists (´\teste/PLACAS.TXT´) then
begin
Assignfile(TEXT,´\teste/PLACAS.TXT´);
Reset(TEXT);
while not Eof(TEXT) do
begin
Readln(TEXT,VALOR);
PLACA:= Copy(VALOR,1,7);
if UPPERCASE(Trim(Edit1.text)) = Trim(PLACA) then
begin
SHOWMESSAGE(´Veículo é da empresa´);
Edit1.text:= ´´;
Edit1.SetFocus;
Closefile(text);
Break;
end
else
begin
Edit2.setfocus;
end;
end;
end
else
Showmessage(´Arquivo não é da empresa.´);
end;

mas qdo quero incluir uma nova placa.. nesta mesmo edit captura a tecla f2 e abro um novo formulario..
aberto este formulário para incluir a placa.. eu incluo ela tudo legal..
[b:058b3a1896]PROBLEMA:[/b:058b3a1896]
EU SO CONSIGO INCLUI UM REGISTRO SE EU NÃO TIVER PASSADO NENHUMA VEZ PELO MÉTODO EXIT DO EDIT...
OU SEJA.. SE EU PASSO UMA VEZ POR ELE E DEPOIS NA PROXIMA VEZ TENTO INCLUIR ELE DÁ ERRO DE I/O ERROR 32

ME AJUDEM EM MAIS ESSA..
OBRIGAGO
ERIC


Eric.miranda

Eric.miranda

Responder

Posts

12/09/2003

Echoesofpinkfloyd

bom dia pessoal estou com um erro com arquivo txt que é o seguinte.. tenho um edit que faço o seguinte.. digito um numero... ele verifica num arquivo txt se o veiculo é da empresa ou não... até ai tudo bem ele faz legal.... este é o código procedure TForm1.Edit1Exit(Sender: TObject); var TEXT: textfile; VALOR,PLACA: string; begin if Fileexists (´\teste/PLACAS.TXT´) then begin Assignfile(TEXT,´\teste/PLACAS.TXT´); Reset(TEXT); while not Eof(TEXT) do begin Readln(TEXT,VALOR); PLACA:= Copy(VALOR,1,7); if UPPERCASE(Trim(Edit1.text)) = Trim(PLACA) then begin SHOWMESSAGE(´Veículo é da empresa´); Edit1.text:= ´´; Edit1.SetFocus; Closefile(text); Break; end else begin Edit2.setfocus; end; end; end else Showmessage(´Arquivo não é da empresa.´); end; mas qdo quero incluir uma nova placa.. nesta mesmo edit captura a tecla f2 e abro um novo formulario.. aberto este formulário para incluir a placa.. eu incluo ela tudo legal.. [b:0d2c477bdc]PROBLEMA:[/b:0d2c477bdc] EU SO CONSIGO INCLUI UM REGISTRO SE EU NÃO TIVER PASSADO NENHUMA VEZ PELO MÉTODO EXIT DO EDIT... OU SEJA.. SE EU PASSO UMA VEZ POR ELE E DEPOIS NA PROXIMA VEZ TENTO INCLUIR ELE DÁ ERRO DE I/O ERROR 32 ME AJUDEM EM MAIS ESSA.. OBRIGAGO ERIC


se a placa é diferente do edit1 o edit2 recebe o foco mas nao fecha o aquivo, experimente fechar o arquivo...se a placa nao existir..,depois posta aqui ... valeu ..


Responder

Gostei + 0

12/09/2003

Bacalhau

o I/O error 32 acontece quando tentamos abrir um arquivo que já está aberto. Significa que o comando CLOSEFILE está mal colocado; repara que o arquivo só fecha se as placas coincidirem. Mudei o closefile para o fim e assim garanto que fecha sempre. Aí vai o código:


procedure TForm1.Edit1Exit(Sender: TObject);

var TEXT: textfile;
VALOR,PLACA: string;

begin
if Fileexists (´\teste/PLACAS.TXT´) then
begin
Assignfile(TEXT,´\teste/PLACAS.TXT´);
Reset(TEXT);
while not Eof(TEXT) do
begin
Readln(TEXT,VALOR);
PLACA:= Copy(VALOR,1,7);
if UPPERCASE(Trim(Edit1.text)) = Trim(PLACA) then
begin
SHOWMESSAGE(´Veículo é da empresa´);
Edit1.text:= ´´;
Edit1.SetFocus;
Break;
end
else
begin
Edit2.setfocus;
end;
end;
end
else
Showmessage(´Arquivo não é da empresa.´);
closefile(TEXT);
end;

abraço
bacalhau


Responder

Gostei + 0

12/09/2003

Bacalhau

Desculpa, enganei-me :oops:

o comando closefile(text) deverá ser colocado ANTES de

else
Showmessage(´Arquivo não é da empresa.´);


Responder

Gostei + 0

12/09/2003

Eric.miranda

valeu galera..
o problema foi resovido com este final de código

end;
end
else
begin
Showmessage(´Arquivo de veículos que ´não podem´ ser autuados não existe´);
end;
closefile(text);
end;

retirando é lógico os closefile anteriores..

valeu pela ajuda
fico devendo mais essa a vcs.


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar