delphi - DGRid showing Selected but no Bookmark -
just found weirdness d5 and/or zeos. have tdbgrid , dataset.
i have "delete" function delete selected rows of dbgrid.
if ctlr-left-click select row (or rows) works fine, but...
if use vertical scrollbar slider move top of dataset shows first row in select color.
if not click top line, (it looks selected) click "delete" crashes. stepping through code, @ first line selectedrows.count displays "1" @ bookmark line "bookmark not found error" if first click on selected row after using slider, not crash.
for i:=0 dbgridaddr.selectedrows.count-1 begin dbgridaddr.datasource.dataset.gotobookmark(pointer(dbgridaddr.selectedrows.items[i]));
how can fix ?
thanks
delphi 5:
you wrote:
if use vertical scrollbar slider move top of dataset shows first row in select color.
even if looks way. not mean evaluated marked.
you can test with:
if dbgridaddr.selectedrows.currentrowselected showmessage('selected') else showmessage('not selected');
description
position markers not automatically removed list when records deleted dataset.
it follows position markers may invalid.
dbgridaddr.selectedrows.refresh;
refresh make sure list contains valid entries.
refresh trying locate records in dataset appear position marker in items property array.
all position marker there no equivalent in amount of data deleted.
if position marker invalid , refresh returns value of true
, makes dbgrid-object invalid redraw triggered, in case invalid records deleted.
if position marker in list should valid, refresh returns value of false
.
never delete items from lists construction.
for i:=0 whatever.count-1 whatever.delete(i);
e.g. consider list 10 items on.
whatever = 0 .. 9
if in "for loop" i = 1
whatever.delete(i);
,
with delete second item.
now whatever
0 .. 8
.
the loop initialized run through 0 9
. can understand if i = 9
whatever.delete(i);
attempts access whatever
outside of 0 .. 8
leads errors.
another example.
you delete incorrect records.
we assume.
before lopp you've identified following items (data record) - number delete.
#3 , #6 , #8
for i:=0 whatever.count-1 if (i=3) or (i=6) or (i=8) whatever.delete(i);
if i=3
following executed whatever.delete(3);
afterwards
row 4 row 3
row 5 row 4
row 6 row 5
, on
now
if... or (i=6) whatever.delete(6);
you delete wrong item, previous row 7 !
also bookmark pointer refers #6, without refresh.
please don't post it better compare content
.
for i:=0 whatever.count-1 if (whatever[i] = 'blue') or (whatever[i] = 'green') or (whatever[i] = 'red') whatever.delete(i);
i know that, it's example show happens when delete items sequence out.
do better way:
for i:= whatever.count-1 downto 0 whatever.delete(i);
so started end delete. lower items keep validity.
edit:
i don't know event of dbgrid using?
to test there no selection, scroll.
close app und restart, nothing scroll dbgrid.
do not click dbgrid !!
press testbutton.
procedure tform1.button2click(sender: tobject); begin if dbgrid1.selectedrows.currentrowselected begin showmessage('selected'); end else begin if dbgrid1.selectedrows.count>0 showmessage(' currentrow not selected'+#13#10+ 'a part in code must have select row.') else showmessage('not selected'); end; end;
Comments
Post a Comment