|
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, ItemTag: Integer; var ItemName: String) 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:
ItemName:
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, ItemTag: Integer; var ItemName: String); begin ItemTag := Integer(StrNew(PChar(Target))); end; This example assumes that rvoTagsArePChars is in Options
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, ItemTag: Integer; var ItemName: String); var FontStyle: TFontInfo; ItemTag := Integer(StrNew(PChar(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, ItemTag: Integer; var ItemName: String); begin ItemTag := Integer(StrNew(PChar(Target))); if DocFormat=rvddURL then StyleNo := rvActionInsertHyperlink1.GetHyperlinkStyleNo(Sender as TRichViewEdit); end;
See also events: See also properties of RVRTFReadProperties: |