|
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: TRVRawByteString) of 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.
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). procedure TMyForm.MyRichViewReadHyperlink(Sender: TCustomRichView; const Target, Extras: String; DocFormat: TRVLoadFormat; var StyleNo: Integer; var ItemTag: TRVTag; var ItemName: TRVRawByteString); var FontStyle: TFontInfo; 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: See also properties of RVRTFReadProperties: |