You must not use RVGetLinearCaretPos here. This function returns a number of characters from the beginning of document to the caret position. But DeleteParas and SetSelectedBounds does not need this value, they need index of item.
The first code could be:
Code: Select all
rve.SearchText('Inicia bloco', [rvseoDown, rvseoWholeWord]);
nPosI := rve.CurItemNo;
rve.SearchText('Termina bloco', [rvseoDown, rvseoWholeWord]);
nPosF := rve.CurItemNo;
rve.DeleteParas(nPosI, nPosF);
It deletes all paragraphs, starting from paragraphs containing the first word and ending to paragraph containing the last word. Document is reformatted, but this change is not written in undo buffer, so it may become invalid, and you need to call rve.ClearUndo.
Do you need to delete reserved words as well? In this case, the second code could be:
Code: Select all
var ItemNoI, ItemNoF, OffsI, OffsF: Integer;
rve.SearchText('Inicia bloco', [rvseoDown, rvseoWholeWord]);
rve.GetSelectionBounds(ItemNoI, OffsI, dummy, dummy, True); // storing the position before selection in ItemNoI, OffsI
rve.SearchText('Termina bloco', [rvseoDown, rvseoWholeWord]);
rve.GetSelectionBounds(dummy, dummy, ItemNoF, OffsF, True);// storing the position after selection in ItemNoF, OffsF
rve.SetSelectionBounds(ItemNoI, OffsI, ItemNoF, OffsF);
rve.DeleteSelection;
Note 1: In a real code, you need to check the result of SearchText to see if the word was really found.
Note 2: These code fragments assume that both words are in the root editor, not in table cells. The second code can be modified to support table cells:
Code: Select all
var ItemNoI, ItemNoF, OffsI, OffsF: Integer;
tle1, tle2: TCustomRichViewEdit;
rve.SearchText('Inicia bloco', [rvseoDown, rvseoWholeWord]);
tle1 := rve.TopLevelEditor;
tle1.GetSelectionBounds(ItemNoI, OffsI, dummy, dummy, True); // storing the position before selection in ItemNoI, OffsI
rve.SearchText('Termina bloco', [rvseoDown, rvseoWholeWord]);
tle2 := rve.TopLevelEditor;
tle2.GetSelectionBounds(dummy, dummy, ItemNoF, OffsF, True);// storing the position after selection in ItemNoF, OffsF
if tle1=tle2 then begin // otherwise, the selection is in different cells
tle2.SetSelectionBounds(ItemNoI, OffsI, ItemNoF, OffsF);
tle2.DeleteSelection;
end;