SafeDeleteItem when only 1 item in cell

General TRichView support forum. Please post your questions here
Post Reply
jimmaguire
Posts: 206
Joined: Thu Sep 15, 2005 1:41 am
Location: California

SafeDeleteItem when only 1 item in cell

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
jimmaguire
Posts: 206
Joined: Thu Sep 15, 2005 1:41 am
Location: California

No - Called DeleteItems(0,1)

Post 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;
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
jimmaguire
Posts: 206
Joined: Thu Sep 15, 2005 1:41 am
Location: California

Post by jimmaguire »

Thanks!
Post Reply