Hyperlink color lost after: WPEditor.AsString := aSavedAsStr

  • Delphi 2007, WPTools [V5.51], Windows Vista

    This question is [sort of] continuation of: http://wpcubed.com/forum/viewtopic.php?t=6130

    Context: In my app, user can select an item from a Popup Menu when he/she clicks on a Hyperlink in WPEditor. The Hyperlink's color is set based on user selection (see Julian's excellent response re: Hyperlink --> Popup Menu:
    http://wpcubed.com/forum/viewtopi…hyperlink+popup)

    Problem: WPEditor can have hyperlinks in different colors based on user selection (e.g., Unmodified = clBlue, UserModified = clNavy, if Embedded text is "Delete Para" then clRed, etc). Problems is that Hyperlink colors are lost after original text is saved and restored (see code below).

    User can "Preview" the output as "PlainText" and on closing Preview, returns to WPEditor. I save WPEditors contents with "AsString", modify contents for preview and finally restore the original contents as shown in the abbreviated code below.

    In form initialization code:

    Code
    With WPEditor.HyperlinkTextAttr do begin    TextColor := clBlue ; {Default color }    {Following must be false so that we can change font color     and underline color in code}    UseTextColor        := false ;    UseUnderlineColor := false ;end;

    "Preview" button.OnClick() -- Abbreviated

    Code
    With WPEditor do begin        { Keep a Copy of WPEditor's Text and CPPos, etc because we are            about to change it. Reset back to normal when exiting            the preview mode }        wpPreview_EditorTextAsString := WPEditor.AsString ;        wpPreview_CPPos := CPPosition ;        wpPreviewTopLineIndex := TopOffset ;       ... {modify WPEditor's contents for preview}       { Display modified text in TMemo as pain text}       aMemo.Text := WPEditor.Text ;end ;

    "Close Preview" button.OnClick() -- Abbreviated

    Interestingly, all text including Hyperlink text and Hyperlink underline color is changed to clBlack (note that default color for Hyperlink is set to clBlue).

    How can we preserve the original Hyperlink color after executing code like above? Any work-arounds?

    Thank You

    JayM

    • Offizieller Beitrag

    Hi,

    In RTF the additional hyperlink attributes are not preserved. They are common in HTML and in WPT format they will also be saved.

    Use AsANSIString('WPT')

    to create a string in WPT format and transfer to a different editor.

    Julian

  • Julian,
    Thank you for your reply. However, using "AsANSIString('WPT')" instead of "AsString" does NOT solve the issue. I am still losing hyuperlink color when I try code like following.

    I may be missing some property assignments, etc., but don't know what!

    Thank you for your help.

    JayM