listview - Register and delete ITEM access database - Delphi -
i sending database, items of listview, after sending have delete item sent.
signing performed normally, problem time delete items. generates following error:
access violation @ address 0073f82e in module "project1.exe". read of address 00000008
what have not generate error. because occurs when try delete files (registration in database occur until item generates error).
if lstbxdados.items.count <= 0 begin exit; end; //try adoconnection1.connected := true; try adocommand1 begin commandtext := 'insert ip (ti_ip, url_ip, ima_ip, desc_ip,id_ip, data_ip, cat_ip,cad_ip) values ( :a, :b, :c, :d, :e, :f, :g, now() )'; := 0 lstbxdados.items.count - 1 begin parameters.parambyname('a').value := trim(lstbxdados.items.item[i].subitems[0]); parameters.parambyname('b').value := trim(lstbxdados.items.item[i].subitems[1]); parameters.parambyname('c').value := trim(lstbxdados.items.item[i].subitems[2]); parameters.parambyname('d').value := trim(lstbxdados.items.item[i].subitems[3]); parameters.parambyname('e').value := trim(lstbxdados.items.item[i].subitems[4]); if trim(lstbxdados.items.item[i].subitems[5]) <> '' begin parameters.parambyname('f').value := strtodate(trim(lstbxdados.items.item[i].subitems[5])); end else begin parameters.parambyname('f').value := null; end; parameters.parambyname('g').value := trim(lstbxdados.items.item[i].subitems[6]); execute; lstbxdados.items.delete(i); end; end; adoconnection1.connected := false; end; //except // respostas(9); //end;
as explained in comments, happens because you're deleting items in loop assumes (because of
for := 0 lstbxdados.items.count - 1
) items.count remains constant, whereas in fact goes down 1 each time delete item. item number [count -1] first time around loop, no longer time it's turn deleted, because there fewer items initial value of count - 1.
solution: use
for := lstbxdados.items.count - 1 downto 0
btw, first thought use while loop:
while lstbxdados.items.count > 0 begin
but see @tlama's comment , careful items array indexing if way.
Comments
Post a Comment