WPCubed Product Support

Parsing RTF Hyperlink information

How can I determine if the current cursor location is in a hyperlink / or the current selection is a hyperlink - fetch the link + text for use in a properties dialog. (I'm assuming I can use the InputHyperlink function to overwrite the existing hyperlink after the user hits ok).

I've tried the SelectionAsString, and this returns the formatted rtf string -- so I'm assuming I need to parse this somehow ... 🙂

#1 ♥ 0
4.6k Views 2 users read 2 min
support

Hi,

I don't think you need to do anything more than to call procedure EditHyperlink(linktext: string = ''). 'linktext' is only used when no text is selected, if it is, it is wrapped into the hyperlink tags.

WPRichText1.EditHyperlink('link');  WPRichText1.SetFocus;

This is the implementation of 'EditHyperlink'

function TWPCustomRichText.EditHyperlink(linktext: string = ''): Boolean;
var obj : TWPTextObj;
    s : string;
begin
  obj := HyperlinkAtCP;
  if obj<>nil then s := obj.Source
  else s := '';
  if InputQuery('Hyperlink','URL',s) then
  begin
     if obj<>nil then obj.Source := s
     else if IsSelected then
       InputHyperlink(s)
     else  InputHyperlink(linktext,s);
     Result := TRUE;
  end else
  Result := FALSE;
end;

Regards,

Julian

BTW: The hyperlinks in version 5 work completely different to the hyperlinks in WPTools 4 (were they were created with double underlined and hidden text).

In V5 they consist of a start> and an end tag, similar to HTML, both represented by a TWPTextObj. You can make this tags visible suing a property in the FormatOptions!

This properties of the TWPTextObj are used:

Source = href
Name = title
ObjType - must be wpobjHyperlink!

#2 ♥ 0
This category is archived. No new posts are possible.