Follow the code:
procedure TfrmGrid.btnLoadClick(Sender: TObject);
var
txt: TextFile;
l,treg,treg2, coo, ccf: integer;
valortxt, valorbd : double;
lTemp, valor, dtcompratxt: String;
dtcompra: TDateTime;
begin
DModuleGrid.ZQuery1.Close;
DModuleGrid.ZQuery1.SQL.Clear;
//Add tdcupant
//numcupom = coo
//Cupons
DModuleGrid.ZQuery1.SQL.Add('SELECT dtcompra, numnf, numcupom, ccf, valor FROM tdcupant');
DModuleGrid.ZQuery1.Open;
DModuleGrid.ClientDataSet1.SetProvider(DModuleGrid.DataSetProvider1);
DModuleGrid.ClientDataSet1.Open;
l:= 1;
treg:= 0;
treg2:= 0;
AssignFile(txt, frmSelection.FileListBox1.FileName);
Reset(txt);
while not eof(txt) do
begin
Readln(txt, lTemp);
if (copy(lTemp, 1, 3) = 'E14') then
begin
inc(treg2);
dtcompratxt := copy(lTemp,65,2)+'/'+copy(lTemp,63,2)+'/'+copy(lTemp,59,4);
TryStrToDateTime(dtcompratxt, dtcompra);
//Comparando valores (Valor do Cupom)
ShowMessage(DModuleGrid.ZQuery1.FieldByName('numcupom').AsString +' '+
copy(lTemp,53, 6));
if (DModuleGrid.ZQuery1.FieldByName('numcupom').AsString = copy(lTemp,53, 6))
and (DModuleGrid.ZQuery1.FieldByName('ccf').AsString = copy(lTemp,47,6))
and (SameDate(DModuleGrid.ZQuery1.ParamByName('dtcompra').AsDate,
dtcompra))
then
begin
inc(treg);
StringGrid1.RowCount := treg+1;
inc(l);
//Valor no BD
StringGrid1.Cells[0,l] := DModuleGrid.ZQuery1.FieldByName('valor').AsString;
valorbd := DModuleGrid.ZQuery1.FieldByName('valor').AsFloat;
//Valor no TXT
StringGrid1.Cells[1,l] := FloatToStr(StrToFloat(copy(lTemp, 109, 14))/100);
valortxt := StrToFloat(copy(lTemp, 109, 14))/100;
ShowMessage(FloatToStr(valortxt) + ' ' + FloatToStr(valorbd));
end;
//Diferença nos valores
if not (StringGrid1.Cells[0,l] = StringGrid1.Cells[1,l]) then
begin
valor := FloatToStr(valorbd - valortxt);
if (valor = '') then
begin
valor := IntToStr(0);
StringGrid1.Cells[2,l] := valor;
end
else
StringGrid1.Cells[2,l] := valor;
end;
end;
end;
ShowMessage('Existem '+ IntToStr(treg2) + ' linhas -E14');
ShowMessage('Existem '+ IntToStr(treg) + ' linhas');
CloseFile(txt);
end;
This code does not reach the second if
, it follows the code of the second if
, which is also above:
dtcompratxt := copy(lTemp,65,2)+'/'+copy(lTemp,63,2)+'/'+copy(lTemp,59,4);
TryStrToDateTime(dtcompratxt, dtcompra);
//Comparando valores (Valor do Cupom)
ShowMessage(DModuleGrid.ZQuery1.FieldByName('numcupom').AsString +' '+
copy(lTemp,53, 6));
if (DModuleGrid.ZQuery1.FieldByName('numcupom').AsString = copy(lTemp,53, 6))
and (DModuleGrid.ZQuery1.FieldByName('ccf').AsString = copy(lTemp,47,6))
and (SameDate(DModuleGrid.ZQuery1.ParamByName('dtcompra').AsDate,
dtcompra))
then
begin
inc(treg);
StringGrid1.RowCount := treg+1;
inc(l);
//Valor no BD
StringGrid1.Cells[0,l] := DModuleGrid.ZQuery1.FieldByName('valor').AsString;
valorbd := DModuleGrid.ZQuery1.FieldByName('valor').AsFloat;
//Valor no TXT
StringGrid1.Cells[1,l] := FloatToStr(StrToFloat(copy(lTemp, 109, 14))/100);
valortxt := StrToFloat(copy(lTemp, 109, 14))/100;
ShowMessage(FloatToStr(valortxt) + ' ' + FloatToStr(valorbd));
end;
This code can not compare the data from one to another.
What am I doing wrong?