Page 1 of 1

Replace hyperlink with new RTF?

Posted: Tue Jun 17, 2025 4:42 pm
by whisper1980
Still evaluating...

I have a case where a user clicks on a hyperlink which causes me to prompt a user on what they want to do. In one case I just replace the current item text with the user's text selection. In another case, I need to completely replace the hyperlink with user selected RTF.

I can't figure out how to delete the hyperlink the user clicked on, positioning the caret at the start of where the hyperlink was, then inserting the new RTF (the inserting is easy, the delete and positioning eludes me).

Thanks for any guidance, and sorry for missing something I should have found in your demos and Help documentation.
Eric

Re: Replace hyperlink with new RTF?

Posted: Tue Jun 17, 2025 5:37 pm
by Sergey Tkachenko
Do you want to do it as an editing operation (undoable?)
If yes, just select the link and insert a new content. The selection will be replaced.

Let the caret is in the item that needs to be replaced, and the new RTF content is in Stream:

Code: Select all

var
  ItemNo, Offs1, Offs2: Integer;
  rve: TCustomRichViewEdit;

// selecting the current item
rve := RichViewEdit1.TopLevelEditor;
ItemNo := rve.CurItemNo;
Offs1 := rve.GetOffsBeforeItem(ItemNo);
Offs2 := rve.GetOffsAfterItem(ItemNo);
rve.SetSelectionBounds(ItemNo, Offs1, ItemNo, Offs2);
// replacing it
Stream.Position := 0;
rve.InsertRTFFromStreamEd(Stream);

Re: Replace hyperlink with new RTF?

Posted: Tue Jun 17, 2025 10:42 pm
by whisper1980
Thanks, Sergey! Works great, and undo works fine as well on it.