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;

Input parameters:

Target – target of hypertext link (Internet address, file name, or bookmark/anchor).

Extras – additional information stored with link. For example, if Extras='\l \o"hint_text"', then Target is an RTF bookmark name (because of '\l') and 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 on drag&drop, when accepting URL dropped to TRichViewEdit (rvddURL must be in AcceptDragDropFormat).

rvlfHTML

The event occurs when reading HTML files using TRVHtmlImporter, if rvhtmloAutoHyperlinks is excluded from RVHtmlImporter.Options.

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 style. If DocFormat=rvlfURL, the initial style may be not hypertext, so you need to provide 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

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.TextStyles.FindSuchStyle(

      StyleNo, FontStyle, RVAllFontInfoProperties);

    if StyleNo<0 then

    begin

      Sender.Style.TextStyles.Add;

      StyleNo := Sender.Style.TextStyles.Count-1;

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

      Sender.Style.TextStyles[StyleNo].Standard := False;

    end;

    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.


RichView © Sergey Tkachenko