rvico TRichView Reference | TRichView

TCustomRichView.OnReadHyperlink

Top  Previous  Next

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

type

  TRVLoadFormat = 

    (rvlfText,rvlfHTML,rvlfRTF,rvlfRVF,rvlfURL);

 

  TRVReadHyperlink = 

    procedure (Sender: TCustomRichView; 

      const Target, Extras: String

      DocFormat: TRVLoadFormat;

     var StyleNo: Integer; var ItemTag: TRVTag

     var ItemName: TRVRawByteStringof object;

 

property OnReadHyperlink: TRVReadHyperlink;

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 containing hyperlinks (RTF loading, pasting, or accepting on drag&drop).

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 using TRVHtmlImporter, if rvhtmloAutoHyperlinks is excluded from RVHtmlImporter.Options.

Or the event occurs when reading HTML files using TRVHtmlViewImporter, if RVHtmlViewImporter.AutoHyperlinks=False.

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: String; DocFormat: TRVLoadFormat;

  var StyleNo: Integer; var ItemTag: TRVTag

  var ItemName: TRVRawByteString);

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: String; DocFormat: TRVLoadFormat;

  var StyleNo: Integer; var ItemTag: TRVTag

  var ItemName: TRVRawByteString);

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: String; DocFormat: TRVLoadFormat;

  var StyleNo: Integer; var ItemTag: TRVTag

  var ItemName: TRVRawByteString);

begin

  ItemTag := Target;

  if DocFormat=rvddURL then

    StyleNo := rvActionInsertHyperlink1.GetHyperlinkStyleNo(Sender as TRichViewEdit);

end;

 

See also events:

OnWriteHyperlink.

See also properties of RVRTFReadProperties:

BasePathLinks.


TRichView © trichview.com