How to delete the last character in the table.cell[0,0]?
Posted: Fri Jan 06, 2017 8:25 am
Support forums for TRichView, ScaleRichView, Report Workshop and RVMedia components
https://writeally.com/forums/
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