How to delete the last character in the table.cell[0,0]?
-
- Site Admin
- Posts: 17564
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17564
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
I am very sorry for the delay.
The task is not as simple as it may seem.
Possible cases:
1) The last item is a text item having more than 1 character.
Action: delete the last character from this item.
2) The last item is a non-text item or a text item containing 1 (or less) characters.
Action: deleting this item. If this item is after a list marker, deleting the marker as well. But if this is the single item in the cell, we replace it with empty text instead.
Call:
PS: I did not test this code properly, if it has bugs, let me know.
The task is not as simple as it may seem.
Possible cases:
1) The last item is a text item having more than 1 character.
Action: delete the last character from this item.
2) The last item is a non-text item or a text item containing 1 (or less) characters.
Action: deleting this item. If this item is after a list marker, deleting the marker as well. But if this is the single item in the cell, we replace it with empty text instead.
Code: Select all
procedure DeleteLastCharacter(RVData: TCustomRVData);
var
ItemNo, ParaNo, TextStyleNo: Integer;
S: String;
begin
if RVData.ItemCount = 0 then
exit;
ItemNo := RVData.ItemCount - 1;
if (RVData.GetItemStyle(ItemNo) < 0) or (Length(RVData.GetItemText(ItemNo)) < 2) then
begin
if (ItemNo > 0) and not ((ItemNo = 1) and (RVData.GetItemStyle(ItemNo - 1) = rvsListMarker)) then
begin
// deleting the last item (non-text or empty or single character)
RVData.DeleteItems(ItemNo, 1);
dec(ItemNo);
// if it was after a list marker, deleting the marker as well
if (ItemNo >= 0) and (RVData.GetItemStyle(ItemNo) = rvsListMarker) then
RVData.DeleteItems(ItemNo, 1);
end
else if RVData.GetItemStyle(ItemNo) < 0 then
begin
// replacing the last non-text item with empty text
ParaNo := RVData.GetItemPara(ItemNo);
TextStyleNo := Min(RVData.GetActualTextStyle(RVData.GetItem(ItemNo)), 0);
RVData.DeleteItems(ItemNo, 1);
RVData.AddNL('', TextStyleNo, ParaNo);
end
else
// deleting the last character of a single character item
RVData.SetItemText(ItemNo, '');
end
else
begin
// deleting the last character from the last text item
S := RVData.GetItemText(ItemNo);
Delete(S, Length(S), 1);
RVData.SetItemText(ItemNo, S);
end;
end;
Code: Select all
DeleteLastCharacter(Table.Cells[0,0].GetRVData);
RichView1.Format; // or you can use BeginItemModify/EndItemModify instead of format