Page 1 of 1

Hyperlink does not work after importing from RTF

Posted: Thu Dec 02, 2010 9:45 am
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;

Posted: Thu Dec 02, 2010 10:08 am
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;

Posted: Thu Dec 02, 2010 11:27 am
by aidadi
Thanks Sergey. Сибирского Вам здоровья)