2
Follows the code:
procedure TfrmGrid.btnLoadClick(Sender: TObject);
var
txt: TextFile;
l, treg : integer;
lTemp: String;
begin
treg := 1;
l:= 0;
AssignFile(txt, lbCaminho.Caption);
Reset(txt);
while not eof(txt) do
begin
Readln(txt, lTemp);
if (copy(lTemp, 1, 3)= 'E14') then
begin
inc(treg);
sgCupons.RowCount:=treg;
inc(l);
//COO
sgCupons.Cells[0,l] := copy(lTemp,53 ,6);
//CCF
sgCupons.Cells[1,l] := copy(lTemp,47 ,6);
//S/N
sgCupons.Cells[2,l] := copy(lTemp,4, 20);
//DATA
sgCupons.Cells[3,l] := copy(lTemp,59, 8);
end;
end;
CloseFile(txt);
ShowMessage('Existem '+IntToStr(treg)+' linhas.');
end;
I made this code in order to read the TXT and assign the sringGrid lines. But the problem now is that I want to prevent the user from reading an improper file like any txt.
So I thought of this code:
AssignFile(txt, lbCaminho.Caption);
Reset(txt);
if (copy(lTemp, 1, 3)= 'E09')
and (copy(lTemp, 1, 3)= 'E10')
and (copy(lTemp, 1, 3)= 'E11')
and (copy(lTemp, 1, 3)= 'E12')
and (copy(lTemp, 1, 3)= 'E13')
and (copy(lTemp, 1, 3)= 'E14')
and (copy(lTemp, 1, 3)= 'E15')
and (copy(lTemp, 1, 3)= 'E21')
then
begin
// O codigo acima viria aqui.
end
else
ShowMessage('Arquivo .TXT inválido.');
CloseFile(txt);
However it enters a loop and says that every txt file is invalid, that is, the input and output error.
Could someone help me?
Is it even a
and
that you want, not aor
? (I don’t understand Delphi, but it seems to me that you’re testing an interval for some possible values - and I’d like you to go intoif
if any of these values are present. I understood right?)– mgibsonbr
He understood certain same friend, but the problem is that even with the 'and' he is giving problems, and recognizes as 'txt invalido', then I tried now with the 'or', but without success.
– Ramon Ruan
Exactly Crood! kkkkk, the msm poblema is the while, I can’t put that if inside the while and close the file twice.
– Ramon Ruan