TRichEdit delete RTF code

General TRichView support forum. Please post your questions here
Post Reply
matteop
Posts: 5
Joined: Fri Oct 05, 2007 10:18 am
Contact:

TRichEdit delete RTF code

Post by matteop »

I've a little RTF file with the following code (created with a TRichEdit component):

Code: Select all

{\rtf1\ansi\ansicpg0\uc1\deff0\deflang0\deflangfe0{\fonttbl{\f0\fnil\fcharset1 Times New Roman;}{\f1\fnil\fcharset1 Arial;}{\f2\fnil\fcharset1 Verdana;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;
\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;
\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;
\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;
\red128\green128\blue128;\red192\green192\blue192;}

\uc1
\pard\fi0\li0\qj\ri0\sb0\sa0\itap0 \plain \f0\fs32 
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0  
\par \pard\fi0\li0\qc\ri0\sb0\sa0\itap0 \plain \f0\b\fs32\cf1 1
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 {\*\bkmkstart p1}{\*\bkmkend p1}
\par \pard\fi0\li0\ql\ri0\sb0\sa0\itap0 \plain \f2\fs20 First chapter, go to {\field{\*\fldinst HYPERLINK ""  \\l "p2"}{\fldrslt \plain \f2\fs20 2}}\plain \f2\fs20 .
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 \plain \f0\fs32  
\par \pard\fi0\li0\qc\ri0\sb0\sa0\itap0 \plain \f0\b\fs32\cf1 2
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 {\*\bkmkstart p2}{\*\bkmkend p2}
\par \pard\fi0\li0\ql\ri0\sb0\sa0\itap0 \plain \f2\fs20 Second chapter, go back to {\field{\*\fldinst HYPERLINK ""  \\l "p1"}{\fldrslt \plain \f2\fs20 1}}\plain \f2\fs20 .
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 \plain \f0\fs32  }
when I load this file into an TRichEdit component the code for the hyperlink is missing and the RTF is:

Code: Select all

{\rtf1\ansi\ansicpg0\uc1\deff0\deflang0\deflangfe0{\fonttbl{\f0\fnil\fcharset1 Arial;}{\f1\fnil\fcharset1 Times New Roman;}{\f2\fnil\fcharset1 Verdana;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;
\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;
\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;
\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;
\red192\green192\blue192;}

\uc1
\pard\fi0\li0\qj\ri0\sb0\sa0\itap0 \plain \f1\fs32 
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0  
\par \pard\fi0\li0\qc\ri0\sb0\sa0\itap0 \plain \f1\b\fs32\cf1 1
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 
\par \pard\fi0\li0\ql\ri0\sb0\sa0\itap0 \plain \f2\fs20 First chapter, go to \plain \f2\fs20 2\plain \f2\fs20 .
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 \plain \f1\fs32  
\par \pard\fi0\li0\qc\ri0\sb0\sa0\itap0 \plain \f1\b\fs32\cf1 2
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 
\par \pard\fi0\li0\ql\ri0\sb0\sa0\itap0 \plain \f2\fs20 Second chapter, go back to \plain \f2\fs20 1\plain \f2\fs20 .
\par \pard\fi0\li0\qj\ri0\sb0\sa0\itap0 \plain \f1\fs32  }
There is a way to avoid this behavior?

Thanks,

Matteo
matteop
Posts: 5
Joined: Fri Oct 05, 2007 10:18 am
Contact:

Post by matteop »

Ok, I Think I've solved parsing Extras instead of using Target in the events:

Code: Select all

procedure TForm1.paragrafoeditWriteHyperlink(Sender: TCustomRichView;
  id: Integer; RVData: TCustomRVData; ItemNo: Integer;
  SaveFormat: TRVSaveFormat; var Target, Extras: String);
begin
   Target := IntToStr((RVData.GetItemTag(ItemNo)));
   Extras := ' \l' + ' "p' + Target + '"';
   Target := '';
end;


procedure TForm1.paragrafoeditReadHyperlink(Sender: TCustomRichView;
  const Target, Extras: String; DocFormat: TRVLoadFormat; var StyleNo,
  ItemTag: Integer; var ItemName: String);
Var p : integer;
    s : string;
begin
   p := Pos('p', Extras);
   s := Copy(Extras, p+1, length(Extras)-p-1);
   ItemTag := StrToInt(s);
end;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In any case, the trial version cannot read bookmarks from RTF, and the latest version does not require processing Extras to save local links.
Post Reply