TCustomRichView.OnReadHyperlink

<< Click to display table of contents >>

TCustomRichView.OnReadHyperlink

Occurs when reading hyperlinks (for example, from RTF file)

type

  TRVReadHyperlink = 

    procedure (Sender: TCustomRichView; 

      const Target, Extras: TRVUnicodeString

      DocFormat: TRVLoadFormat;

     var StyleNo: Integer; var ItemTag: TRVTag

     var ItemName: TRVUnicodeStringof object;

 

property OnReadHyperlink: TRVReadHyperlink;

(changed in version 18)

By default, hyperlink targets is saved in the item tag. Use this event to customize loading.

Input parameters:

Target target of hypertext link (for example, an Internet address, a file name, or a bookmark/anchor).

Extras additional information stored with link. For example, if Extras='\o"hint_text"', then Target is read from RTF and the link has a popup hint 'hint_text'.

TRichView automatically writes items hints in rvespHint item's extra string property, and adds '#' to the beginning of links to bookmarks.

DocFormat – format of loaded document.

DocFormat

Meaning

rvlfRTF

The event occurs when reading RTF files (or streams) containing hyperlinks (RTF loading, pasting, or accepting on drag&drop).

rvlfDocX

The event occurs when reading DocX (Microsoft Word Document) files containing hyperlinks

rvlfURL

The event occurs:

1) on drag&drop, when accepting URL dropped to TRichViewEdit (rvddURL must be in AcceptDragDropFormats).

2) when pasting from the Clipboard, when pasting URL to TRichViewEdit (rvddURL must be in AccepPasteFormats).

rvlfHTML

The event occurs when reading HTML files containing hyperlinks.

StyleNo:

if the item is a picture, it is initially equal to rvsHotPicture. You can change it to rvsPicture, if you want to disable this link.

if the item is a text, it is index of style of this text. You can modify it to point to another (hypertext) style. If DocFormat=rvlfURL, the initial style may be not hypertext, so you need to provide the index of hypertext style in this parameter.

ItemName:

if the item is a picture, it is initially equal to '' (empty string) . You can set it to value which will be assigned to name of this item.

if the item is a text, it is initially a text to display. You can modify it.

 

Output parameters:

StyleNo style that will be used for the loaded item. See comments for input parameters.

ItemName value that will be assigned to item text. See comments for input parameters.

ItemTag value that will be assigned to tag of this item. A good place to store hyperlink target.

 

Example 1

This example does the same work as it the event is not assigned: reading the link target in the item tag.

procedure TMyForm.MyRichViewReadHyperlink(Sender: TCustomRichView; 

  const Target, Extras: TRVUnicodeString; DocFormat: TRVLoadFormat;

  var StyleNo: Integer; var ItemTag: TRVTag

  var ItemName: TRVUnicodeString);

begin

  ItemTag := Target;

end;

 

More complicated example

This example assumes that you included rvddURL in AcceptDragDropFormat and want to accept hyperlinks. Besides, it's assumed that "Allow adding styles dynamically" is set in the component editor (or properties are set to the proper values to allow saving the changed collection of text styles).
This code uses blue underlined font for hyperlinks.

procedure TMyForm.MyRichViewReadHyperlink(Sender: TCustomRichView; 

  const Target, Extras: TRVUnicodeString; DocFormat: TRVLoadFormat;

  var StyleNo: Integer; var ItemTag: TRVTag

  var ItemName: TRVUnicodeString);

var FontStyle: TFontInfo;
begin

  ItemTag := Target;

  if DocFormat=rvddURL then

  begin

    FontStyle := TFontInfo.Create(nil);

    FontStyle.Assign(Sender.Style.TextStyles[StyleNo]);

    FontStyle.Color := clBlue;

    FontStyle.Style := FontStyle.Style + [fsUnderline];

    FontStyle.Jump := True;

    StyleNo := Sender.Style.FindTextStyle(FontStyle);

    FontStyle.Free;

  end;

end;

The same example using RichViewActions:

procedure TMyForm.MyRichViewReadHyperlink(Sender: TCustomRichView; 

  const Target, Extras: TRVUnicodeString; DocFormat: TRVLoadFormat;

  var StyleNo: Integer; var ItemTag: TRVTag

  var ItemName: TRVUnicodeString);

begin

  ItemTag := Target;

  if DocFormat=rvddURL then

    StyleNo := rvActionInsertHyperlink1.GetHyperlinkStyleNo(

      Sender as TRichViewEdit);

end;

 

See also events:

OnWriteHyperlink.

See also properties of RVRTFReadProperties:

BasePathLinks.