Inserting and deleting Hyperlinks

  • Hi there,

    I'm having trouble deleting hyperlinks. To prevent users from changing the hyperlink text, i protect the text. If i delete the hyperlink, one protected character (a space) is left behind and i cannot seem to get rid of it.

    Here's my code (sample only, no checks are performed, etc):

    Editor options:
    wpdllInt1.Memo.SetBProp( BPropSel.wpVarBOptions, 7, BPropVal.on); //One-click hyperlinks
    wpdllInt1.Memo.SetBProp( BPropSel.wpEditOptions, 23, BPropVal.on); //Auto detect www
    wpdllInt1.Memo.SetIProp( (int)MemoIProp.HyperlinkCursor, (int)MemoCursor.HandPoint ); //Handpoint cursor for hyperlinks
    wpdllInt1.Memo.SetBProp(BPropSel.wpProtectProp, 4, BPropVal.on); //Protect protected text


    To insert a hyperlink i use the following code:

    //Make sure there is a space between the hyperlink and the existing text
    char currentChar = (char)wpdllInt1.Memo.CurrPar.GetChar( wpdllInt1.Memo.TextCursor.CPPosition-1 );
    if( currentChar != 0 && currentChar != ' ' )
    wpdllInt1.TextCursor.InputText(" ");

    wpdllInt1.Memo.CurrAttr.SetStyles(8192); //Protect the link
    wpdllInt1.TextCursor.InputHyperlink("HyperlinkCommand", "Hyperlink", false);
    wpdllInt1.Memo.CurrAttr.ExcludeStyles(8192); //Text after link should be unprotected
    wpdllInt1.TextCursor.InputText(" ");


    Whenever the user clicks on the link, a popup menu appears, selecting the link and showing a 'Delete Link' option.
    private void wpdllInt1_OnHyperlink(object Sender, int Editor, string URL, IWPTextObj TextObj)
    {
    TextObj.Select(2);
    popupMenu1.ShowPopup(MousePosition);
    }


    To delete the link, i'm using the code:

    wpdllInt1.Memo.TextCursor.DisableProtection();
    wpdllInt1.Memo.TextCursor.InputText("\b"); //Since hyperlink was selected in _OnHyperlink event, i simply input a Backspace character.
    wpdllInt1.Memo.TextCursor.EnabledProtection();

    I've tried to use wpdllInt1.Memo.TextCursor.InputText("\b"); multiple times but this does not work.

    note: Whenever i leave the protection disabled (ie not using EnabledProtection) i can manually type BS, BS to delete the hidden protected char.

    Thanks,
    Richard

    • Offizieller Beitrag

    Hi,

    the editor is not prepared to support protecting the links. The deletion is also not so easy since a link always contain of a start and an end object, the text inbetween is the displayed text,.

    Do you need to remove the link completely or just to convert the link into regular text ?

    Julian

  • Thanks Julian,

    I would like to completely remove the hyperlink (incl text).

    The hyperlink is to show a field from a specific record that was selected by the user (Say a Name and phone number from a contact record).

    The Hyperlink command (URL parameter when using InputHyperlink) actually contains the query. Before the editor/form is shown i update all hyperlinks by executing their commands/querys and set the EmbeddedText to the query result.

    If the hyperlink is not protected, users may accidentally modify the hyperlink text (a phone nr) before printing the it. I could refresh the hyperlinks before saving,printing, etc. but not allowing users to change it seems to make more sense.