• I have set the properties of the hyperlinktextattr for a richtext to

    HyperlinkTextAttr.Underline = tsFALSE
    HyperlinkTextAttr.NotUsedForSpellAsYouGo = True
    HyperlinkTextAttr.UnderlineColor = clBlue
    HyperlinkTextAttr.TextColor = clHighlight
    HyperlinkTextAttr.UseUnderlineColor = True
    HyperlinkTextAttr.UseTextColor = True
    HyperlinkTextAttr.HotUnderlineColor = clRed
    HyperlinkTextAttr.HotTextColor = clHighlight
    HyperlinkTextAttr.UseHotTextColor = True
    HyperlinkTextAttr.HotUnderline = tsFALSE
    HyperlinkTextAttr.HotEffect = wpeffPopup
    HyperlinkTextAttr.HotStyleIsActive = True
    HyperlinkTextAttr.HotEffectColor = clBtnFace

    This all works fine in general. However, I have pasted a document from MS Word into the richtext and if I insert a hyperlink using hyperlinktextattr inside that text the text does not appear highlighted. The hover effects work however. Any ideas why that might be happening? any work around?

    It doesn't happen with all text pasted into the rich text just certain texts.

    • Offizieller Beitrag

    Hi,

    Word is, in contrast to WPTools, actually applying the text attributes to the hyperlinks. They are not dynamic. So, when you copy text from Word the text attributes have been fixed and cannot be set trough the surrounding hyperlink tags anymore.

    With OnBeforePasteEvent text can be pre-processed before it is made visible.

    Julian

  • Julian,

    I am pasting text from word and after pasting, I am inserting a new hyperlink inside the pasted text using inputhyperlink. Does the hyperinktextattr not override the pasted word attributes?

    If not, what do I need to do in the onBeforePateEvent so stop pasted text overriding the hyperlinktextattr? I wouldn't know where to begin!

    Thanks

    Mark

  • Julian,

    I have looked at the BeforePasteEvent.

    I assume that I work with the rtfData paramter and do something like

    Code
    var p:TParagraph;
    begin
      p:=RTFData.FirstPar;
      while assigned(p) do
        begin
    	[Get the fields and reset the attribute]
          p:=p.NextPar;
        end;

    However, I am not quite sure if this is right and, if so, how I get a reference to the hyperlink objects in each para.

    I have checked the help file I downloaded with version 7 (in chm format) and it seems to be broken, clicking on the document indexes does not open the relevant help. I have found the WPTools7 manual online, but I couldn't find anything which helped. Can you please point me in the right direction as to what I need to do here? Can you also tell me where I can find the help file for download in chm format?

    Thanks

    • Offizieller Beitrag

    I strongly recommend to check out the provided source code. Esspeically WPctrMemo.pas

    This is the docu for the beforepaste event:

    This event is executed after text was loaded from the clipboad and before
    it is inserted at the cursor position.
    This event makes it possible to modify the text before it is inserted!
    <br>
    This Example changes the attributes of the inserted text to 'Courier, 10.5, blue':
    <code>
    procedure TForm1.WPRichText1BeforePasteText(Sender: TObject;
    RTFData: TWPRTFDataCollection; par: TParagraph; Stream: TStream;
    Reader: TWPCustomTextReader; OnlyBodyText: Boolean;
    var LoadedText: TWPRTFDataBlock);
    var i : Integer;
    CharAttrIndex : Cardinal;
    begin
    // This is an example to change the format
    // of all inserted text to a given font and size

    // 'AttrHelper' is our working horse to create the attribute
    RTFData.RTFProps.AttrHelper.Clear;
    RTFData.RTFProps.AttrHelper.SetFontName('Courier New');
    RTFData.RTFProps.AttrHelper.SetFontSize(10.5);
    RTFData.RTFProps.AttrHelper.SetColor(clBlue);
    CharAttrIndex := RTFData.RTFProps.AttrHelper.CharAttr;

    // At this point we can calculate another CharAttrIndex

    while par<>nil do
    begin
    for i:=0 to par.CharCount-1 do
    begin
    par.CharAttr[i] := CharAttrIndex;
    end;
    par := par.next;
    end;
    end;
    </code>

    To access the hyperlinks you can read the TextObject[i] and check the objecttype and the property. The hyperlink use tpye = wpobjHyperlnk and the url in is propert Source.