2
Follows the code:
// Leitura Dados Itens da Nota Fiscal...
xmlNCab := NoPrinc.ChildNodes.FindNode('det');
while not (xmlNCab = Nil) do
begin
inc(l);
sgProds.RowCount := l;
//xmlNCab.ChildNodes.FindNode('det');
xmlNItm := xmlNCab.ChildNodes['prod'];
cProd := xmlNItm.ChildNodes['cProd' ].Text; // Código do produto CFOP
xProd := xmlNItm.ChildNodes['xProd' ].Text; // Nome do produto
uCom := xmlNItm.ChildNodes['uCom' ].Text; // Sigla unidade da embalagem
qCom := xmlNItm.ChildNodes['qCom' ].Text; // Quantidade do produto (4dec,S/M)
vUnCom := xmlNItm.ChildNodes['vUnCom'].Text; // Valor unitário do produto (4dec,S/M)
vProd := xmlNItm.ChildNodes['vProd' ].Text; // Valor total do produto (2dec,S/M)
sgProds.Cells[0,l] := cProd;
sgProds.Cells[1,l] := xProd;
sgProds.Cells[2,l] := uCom;
sgProds.Cells[3,l] := qCom;
sgProds.Cells[4,l] := vUnCom;
sgProds.Cells[5,l] := vProd;
DataModule1.zqInsertXML.Close;
DataModule1.zqInsertXML.SQL.Clear;
DataModule1.zqInsertXML.SQL.Add('INSERT INTO xmlprod(cProd, xProd, uCom, qCom, ' + 'vUnCom, vProd, chval)');
DataModule1.zqInsertXML.SQL.Add('VALUES (:pcProd, :pxProd, :puCom, :pqCom, ' + ':pvUnCom, :pvProd, :pchval)');
DataModule1.zqInsertXML.ParamByName('pcProd').AsString := cProd;
DataModule1.zqInsertXML.ParamByName('pxProd').AsString := xProd;
DataModule1.zqInsertXML.ParamByName('puCom').AsString := uCom;
DataModule1.zqInsertXML.ParamByName('pqCom').AsString := qCom;
DataModule1.zqInsertXML.ParamByName('pvUnCom').AsString := Trcpv(vUnCom);
DataModule1.zqInsertXML.ParamByName('pvProd').AsString := Trcpv(vProd);
DataModule1.zqInsertXML.ParamByName('pchval').AsString := cnpj+fone;
DataModule1.zqInsertXML.ExecSQL;
xmlNCab := xmlNCab.NextSibling;
end;
This code above is just a small continuation of the answer to this previously asked question: Access Violation When Selecting XML File - Nfe
And I believe the error is in this while, because it selects my xml items, however, when it has only one item, it selects more than necessary, ie, adds somehow, empty items.
Here’s a picture of what happened:
Any idea?