I'm not in favor of giving the fish to the crowd, so I'll try to teach you how to fish:
We have the following text file, called test.txt ( which should be in the same folder as the executable, to facilitate our test ):
123456789012345678901234567890
COL1 COL2 COL3
DADO1 DADO2 DADO3
TESTE1 TESTE2 TESTE3
Note that the 123456789012345678901234567890
line should not go to the text file, consider it a ruler, assuming that the TXT you are working on is typed.
Considering that your txt is small, we will use a StringList
to capture the data of it as follows:
procedure TForm1.Button1Click(Sender: TObject);
var
arquivo : TStringList;
i : integer;
begin
arquivo := TStringList.Create;
arquivo.LoadFromFile('teste.txt');
end;
Now your file is all in StringList
File and is ready to be compared with any value as follows:
for i := 0 to arquivo.Count - 1 do
begin
Showmessage('Primeiro campo: ' + copy(arquivo[i],1,10)); //Primeiro Campo
Showmessage('Segundo campo: ' + copy(arquivo[i],11,10)); //Segundo Campo
Showmessage('Terceiro campo: ' + copy(arquivo[i],21,10)); //Terceiro Campo
end;
From here on you get the insertion in StringGrid
, the validation and use of the DLL of Bematech, Daruma or whatever the manufacturer. The created loop will go through all StringList
. Remember that it starts at 0 and goes to arquivo.count - 1
by the index of TStringList
if it starts at 0 and not at 1.