rvico TRichView Reference | TRichView

TCustomRichView.OnWriteHyperlink

Top  Previous  Next

Occurs when RichView wants to save hypertext link to HTML or RTF file

type

  TRVWriteHyperlink = procedure (Sender: TCustomRichView;

     id: Integer; RVData: TCustomRVData; ItemNo: Integer;

     SaveFormat: TRVSaveFormat;

     var Target, Extras: Stringof object;

 

property OnWriteHyperlink: TRVWriteHyperlink;

(introduced in v1.8)

By default, items tags are saved as targets of hypertext links in RTF and HTML.

But you can use this event to customize saving.

In order to do it, you need to assign Target parameter to the target URL.

 

Input parameters:

id – identifier of the hypertext link; this event can be called for unformatted documents; in this case, id=-1.

RVData – document containing hyperlink (it may be Sender.RVData, or table cell, or cell inplace editor's RVData)

ItemNo – index of the hyperlink-item inside RVData.

SaveFormat can be rvsfHTML or rvsfRTF.

 

Output parameters:

Target – hyperlink target to save in file or stream. If you return an empty string, this item will not be saved as a hyperlink.

Extras – optional additional information for saving with the link.

Example 1:

This example does the same work as if the event is not assigned: saves the item tag as a target.

procedure TMyForm.MyRichViewWriteHyperlink(

  Sender: TCustomRichView; id: Integer;

  RVData: TCustomRVData; ItemNo: Integer;

  SaveFormat: TRVSaveFormat;

  var Target, Extras: String);

begin

  Target := RVData.GetItemTag(ItemNo);

end;

Example 2:

The same, but in addition to saving the link target, this example saves the hint "Click here!" (both for RTF and HTML) and the attribute "target=_blank" for HTML.

procedure TMyForm.MyRichViewWriteHyperlink(

  Sender: TCustomRichView; id: Integer;

  RVData: TCustomRVData; ItemNo: Integer;

  SaveFormat: TRVSaveFormat;

  var Target, Extras: String);

begin

  Target := RVData.GetItemTag(ItemNo);

  case SaveFormat of

    rvsfHTML:

      Extras := 'target=_blank title="Click here!"';

    rvsfRTF:

      Extras := '\o "Click here!"';

  end;

end;

Saving hint is given here only as an example. TRichView saves hints stored in the rvespHint item's extra string property automatically.

 

Example 3:

procedure TMyForm.MyRichViewWriteHyperlink(

  Sender: TCustomRichView; id: Integer;

  RVData: TCustomRVData; ItemNo: Integer;

  SaveFormat: TRVSaveFormat;

  var Target, Extras: String);

begin

  case id-FirstJumpNo of

    0: Target := 'http://www.borland.com';

    1: Target := 'http://www.inprise.com';

    2: Target := 'http://www.codegear.com';

    3: Target := 'http://www.embarcadero.com';

  end;

end;

 

See also events:

OnReadHyperlink.

See also methods:

SaveHTML;

SaveHTMLEx;

SaveRTF;

(and methods saving RTF and HTML to streams).

See also:

Hypertext;

Saving to HTML.


TRichView © trichview.com