Page 1 of 1

SafeDeleteItem when only 1 item in cell

Posted: Sat Dec 08, 2007 9:49 pm
by jimmaguire
My merge forms consists of tables and multi-line merge fields are often the only item in a cell, so when I do a DeleteItems the ItemNo = -1, so I changed SafeDeleteItems to

else
ItemNo := 0

That seems to work. Any suggestions?

Posted: Mon Dec 10, 2007 1:47 pm
by Sergey Tkachenko
Why do you call DeleteItems(-1)? It makes no sense. Items are indexed from 0 to ItemCount-1.
If you deleted the last item in the table cell, you should insert something instead (Cell.AddNL('', 0, 0), for example)

No - Called DeleteItems(0,1)

Posted: Mon Dec 10, 2007 11:06 pm
by jimmaguire
ItemNo = 0 when I call SafeDeleteItem, because there is only one item, so the dec(ItemNo) line in SafeDeleteItem made it -1. So then the If... is not true, so I added an else to set it to 0.

I believe the ItemNo = 0 is correct because its a zero based array with one item. See my else below.


procedure TLetterMergeForm.SafeDeleteItem(RVData: TCustomRVData; var ItemNo: Integer);
var BR, PB, PS: Boolean;
begin
PS := RVData.IsParaStart(ItemNo);
BR := RVData.IsFromNewLine(ItemNo) and not PS;
PB := RVData.PageBreaksBeforeItems[ItemNo];
RVData.DeleteItems(ItemNo, 1);
dec(ItemNo);

if (ItemNo<RVData.ItemCount) and (ItemNo>=0) then
begin
RVData.GetItem(ItemNo).SameAsPrev := not PS;
RVData.GetItem(ItemNo).BR := BR;
RVData.GetItem(ItemNo).PageBreakBefore := PB;
end else
ItemNo := 0;
end;

Posted: Tue Dec 11, 2007 12:04 pm
by Sergey Tkachenko
The line dec(ItemNo) must be removed.
When you delete the ItemNo-th item, the next item (if it exists) becomes the ItemNo-th item, and you should change its properties, not properties of the previous item.
As for value of ItemNo parameter after existing this procedure, it depends on your needs (probably ItemNo should not be a var-parameter at all)

Posted: Tue Dec 11, 2007 6:41 pm
by jimmaguire
Thanks!