Hyperlink does not work after importing from RTF

General TRichView support forum. Please post your questions here
Post Reply
aidadi
Posts: 2
Joined: Thu Dec 02, 2010 7:25 am

Hyperlink does not work after importing from RTF

Post by aidadi »

Why hyperlink does not work when I click it after importing from RTF (LoadRTF)? I use the following procedure:

Code: Select all

procedure TForm1.RichViewEdit1Jump(Sender: TObject; id: Integer);
var URL: String;
    RVData: TCustomRVFormattedData;
    ItemNo: Integer;
begin
  RichViewEdit1.GetJumpPointLocation(id, RVData, ItemNo);
  URL := PChar(RVData.GetItemTag(ItemNo));
  ShellExecute(0, 'open', PChar(URL), nil, nil, SW_SHOW);
end;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

To import hyperlinks from RTF, you need also OnReadHyperlink event.
To export hyperlinks to RTF and HTML, you need also OnWriteHyperlink events.
If you use RichViewActions, copy a code for these events from the ActionTest project.
If not, use this code:

Code: Select all

procedure TForm1.RichViewEdit1ReadHyperlink(Sender: TCustomRichView; const Target,
  Extras: String; DocFormat: TRVLoadFormat; var StyleNo, ItemTag: Integer;
  var ItemName: TRVRawByteString);
begin
  ItemTag := Integer(StrNew(PChar(Target)));
end;

procedure TForm1.RichViewEdit1WriteHyperlink(Sender: TCustomRichView; id: Integer;
  RVData: TCustomRVData; ItemNo: Integer; SaveFormat: TRVSaveFormat;
  var Target, Extras: string);
begin
  Target := PChar(RVData.GetItemTag(ItemNo));
end;
Update 2011-Oct-22:
For TRichView 13.3+, the code must be:

Code: Select all

procedure TForm1.RichViewEdit1ReadHyperlink(Sender: TCustomRichView; const Target,
  Extras: String; DocFormat: TRVLoadFormat; var StyleNo: Integer;
  var ItemTag: TRVTag;
  var ItemName: TRVRawByteString);
begin
  ItemTag := Target;
end;

procedure TForm1.RichViewEdit1WriteHyperlink(Sender: TCustomRichView; id: Integer;
  RVData: TCustomRVData; ItemNo: Integer; SaveFormat: TRVSaveFormat;
  var Target, Extras: string);
begin
  Target := RVData.GetItemTag(ItemNo);
end;
Last edited by Sergey Tkachenko on Sat Oct 22, 2011 6:26 pm, edited 1 time in total.
aidadi
Posts: 2
Joined: Thu Dec 02, 2010 7:25 am

Post by aidadi »

Thanks Sergey. Сибирского Вам здоровья)
Post Reply