<< Click to display table of contents >> TCustomRichView.OnWriteHyperlink |
Occurs when TRichView wants to save hypertext link to HTML, Markdown, RTF or DocX file
type
TRVWriteHyperlink = procedure (Sender: TCustomRichView;
id: Integer; RVData: TCustomRVData; ItemNo: Integer;
SaveFormat: TRVSaveFormat;
var Target, Extras: TRVUnicodeString) of object;
property OnWriteHyperlink: TRVWriteHyperlink;
(introduced in v1.8; changed in version 18)
By default, items tags are saved as targets of hypertext links in RTF, DocX, HTML, and Markdown.
But you can use this event to customize saving.
In order to do it, assign the target URL to the Target parameter.
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 rvsfHTML or rvsfRTF or rvsfDocX
Output parameters:
Target – hyperlink target to save in a file or a 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: TRVUnicodeString);
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: TRVUnicodeString);
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: TRVUnicodeString);
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:
See also methods:
▪SaveHTML;
▪SaveRTF;
▪SaveDocX;
▪(and methods saving these formats to streams).
See also: