Follow 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 only a small continuation of the answer to this earlier question: Access Violation When Selecting XML File - NFe
And I believe that the error is in this while, because it selects items from my xml, but when it has only one item, it selects more than necessary, that is, it adds some empty items.
Here's what happened:
Any ideas?