Assign RTF String to TfrxRichView

Fast Report GURUS,

I have several DB fields, which when combined together create a valid RTF format. The resulting string then must be bound to a given TfrxRichView.

The following is my code. Please advise as to what is wrong. The code runs with no errors, but is invalid. Is their a simpler way?

procedure rtfStep07_34OnBeforePrint(Sender: TfrxComponent);
var
lStream : TMemoryStream;
lStr : string;
begin
rtfStep07_34.RichEdit.Lines.Clear;
rtfStep07_34.RichEdit.PlainText := False;

lStr := <GRP_APP_STEP_07."APPID_34_NOTE_RTF">
+ <GRP_APP_STEP_07."APPID_34_NOTE2_RTF2">
+ <GRP_APP_STEP_07."APPID_34_NOTE3_RTF3">;
lStream := TMemoryStream.Create;
try
// Saving string to the stream
lStream.Write(lStr, Length(lStr));
lStream.Position := 0;
rtfStep07_34.RichEdit.Lines.LoadFromStream( lStream );
finally
lStream.Free;
end;
end;

Comments

  • LurkingKiwiLurkingKiwi Wellington, New Zealand
    edited 12:32AM
    The following is my code. Please advise as to what is wrong. The code runs with no errors, but is invalid. Is their a simpler way?

    In what way is it invalid?

    I do something similar with a stream in Delphi XE (not FastScript) for the standard Delphi Richtext component, and found I had to do the following:
    - Ensure there was no leading whitespace before the { which opens the RTF, this was an import issue
    - Convert the string to ANSI 8-bit (not the usual Unicode string)
    - I used ms.WriteBuffer to send the string contents to the stream, maybe there's no other way to send 8-bit characters
    - I had to toggle the wordwrap flag to get the text to wrap after loading

    The RTF is fetched from an SQLite database using a local shim.
    var
    Notes: ansistring;
    ms:TMemoryStream;
    
    begin
    Notes := AnsiString(sltb.FieldAsString(sltb.FieldIndex['rtf_text']));
    ms:=TMemoryStream.create;
    ms.WriteBuffer(Pointer(Notes)^, Length(Notes));
    ms.Position := 0;
    reNote.Lines.LoadFromStream(ms);
    reNote.WordWrap := false;
    reNote.WordWrap := true;
    ms.Free;
    

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.