Page 1 of 1

Can't save Hyperlink to database

Posted: Wed Oct 08, 2008 8:47 am
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)

Posted: Wed Oct 08, 2008 12:07 pm
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.

Posted: Fri Oct 10, 2008 7:17 am
by thomasvonkapellen
Works fine,

Thanks