Can't save Hyperlink to database

General TRichView support forum. Please post your questions here
Post Reply
thomasvonkapellen
Posts: 6
Joined: Wed Oct 08, 2008 8:30 am

Can't save Hyperlink to database

Post by thomasvonkapellen »

Hi,

I'm trying to save hyperlink information into a mysql database using TDBRichViewEdit.

First I used the sourcecode of the "CreateHyperlinks"-Demo, then I used the following line:

Code: Select all

rve.AddNLTag('Hyperlink example', 3, -1, Integer(StrNew('http://www.trichview.com')));
Ok, inserted the hyperlink, saved with post to database, but then the hyperlink info was vanished.

The main difference to the demo was, that I set FieldFormat to "rvdbRTF", because I want to save the data in Rtf-Format.

So how can I do that? Any suggestions or is it just not possible to store hyperlink Infos with this component in RTF-Format?

Thanks

Tom


(TRichViewEdit v10.4, Delphi 2006, WindowsVista)
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Hyperlinks are not saved and loaded in RTF automatically. Use OnReadHyperlink and OnWriteHyperlink events.
Copy the following implementation of these events to your application:

Code: Select all

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

procedure TfrmMain.rveWriteHyperlink(Sender: TCustomRichView; id: Integer;
  RVData: TCustomRVData; ItemNo: Integer; SaveFormat: TRVSaveFormat;
  var Target, Extras: string);
begin
  Target := PChar(RVData.GetItemTag(ItemNo));
end;
Saving/writing URLs in RTF was not implemented automatically because programmer may choose to store additonal information in tags, not only hyperlinks.

(and make sure that rvoTagsArePChars is included in rve.Options)

Update 2011-Oct-22:
Starting from TRichView 13.3, the code must be

Code: Select all

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

procedure TfrmMain.rveWriteHyperlink(Sender: TCustomRichView; id: Integer; 
  RVData: TCustomRVData; ItemNo: Integer; SaveFormat: TRVSaveFormat; 
  var Target, Extras: string); 
begin 
  Target := RVData.GetItemTag(ItemNo); 
end;
And rvoTagsArePChars is not used.
Last edited by Sergey Tkachenko on Sat Oct 22, 2011 6:44 pm, edited 1 time in total.
thomasvonkapellen
Posts: 6
Joined: Wed Oct 08, 2008 8:30 am

Post by thomasvonkapellen »

Works fine,

Thanks
Post Reply