RichEdit replace string without lost.

edited 11:03PM in FastReport 3.0
Hello all,

I want replace string in RichEdit before print with FastReport. I load file to RichEdit object, but when replace string lost a format of document.

Please see source below!
Can I fix this?

Thanks.

var
RichView: TfrxRichView;

begin
Form229.frxReport1.Clear;
Form229.frxReport1.LoadFromFile( 'spr0059.fr3' );

RichView := TfrxRichView( Form229.frxReport1.FindObject( 'Rich1' ) );
If RichView <> Nil Then Begin
RichView.RichEdit.Lines.LoadFromFile( 'doc.rtf' );
RichView.RichEdit.Lines.Text := RepStr( RichView.RichEdit.Lines.Text,'$rival_docnom$','123' );
// when replace string lost text formating of RichEdit and FastReport show it at PlanText !!! Any Ideas!


RichView.RichEdit.SelStart := 0;
RichView.RichEdit.SelLength := Length( RichView.RichEdit.Text );
RichView.RichEdit.SelAttributes.Name := Form3.aSystem[33];
RichView.RichEdit.Font.Size := 10;
End;

Form229.frxReport1.ShowReport( True );

end;



function RepStr( cStr,cRemove,cReplace: String ) : String;
var
cNew: String;
begin
Result := '';
cNew := cStr;
Repeat
cNew := StuffString( cNew,Pos( cRemove,cNew ),Length( cRemove ),cReplace );
Until Pos( cRemove,cNew ) = 0;

Result := cNew;
end;

Comments

  • edited July 2006
    use RichView.RichEdit.Lines.Add() or RichView.RichEdit.Lines.Insert( )
    instead of RichView.RichEdit.Lines.Text := RepStr( RichView.RichEdit.Lines.Text,'$rival_docnom$','123' );
  • edited 11:03PM
    How to do that???
    Give me a sample.

    When use .Add() addet lines in RichEdit is a plantext not in Rich format. When use Loadfromfile() all is ok.

    Thanks.
  • edited 11:03PM
    I slove the problem...




    RichView.RichEdit.Lines.LoadFromFile( ExtractFilePath( Application.ExeName ) + 'doc.rtf' );

    SearchAndReplace( RichView.RichEdit,'$rival_docnom$','123' );
    SearchAndReplace( RichView.RichEdit,'$rival_docdate$','11.01.2005' );


    procedure SearchAndReplace( Rich: TrxRichEdit; InSearch,InReplace: String );
    var
    X,ToEnd: Integer;
    begin
    X := 0;
    ToEnd := Length( Rich.Text );
    X := Rich.FindText( inSearch,X,ToEnd,[] );

    While X <> -1 Do Begin
    Rich.SelStart := X;
    Rich.SelLength := Length( inSearch );
    Rich.SelText := inReplace;
    X := Rich.FindText( inSearch,X + Length( inReplace ),ToEnd,[] );
    End;
    end;

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.