Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

DBRichEdit- forcing a font

edited March 2003 in General
Is it possible to force a font on a DBRichEdit component? This would
provide a consistent font regardless of what the user has entered in the
memo field.

I've tried to use an RBDBRichedit, (which allows control of the font)
only to have problems with it misinterpreting characters, and going into
an endless loop.


Thanks,

John

Comments

  • edited March 2003
    Below are two articles which show some code to help you out. Furthermore,
    RB's rich edit architecture relies on Delphi's TRichEdit. The "Sel" (select)
    methods and properties available on our rich text controls allow you to
    perform operations on the rich text, such as SelectAll and change the
    selected font to be one single font overriding the memo contents in the
    database. A solution is to use the TppDBRichText.OnGetRichText event in
    order to control the loading of the rich text yourelf from the database BLOB
    field and stream it to the TppDBRichText. Please take a look at the rich
    text demos in the main reports demos project in the RBuilder installation
    folder. You could also manually load the rich text to a TppRichText object
    from the BLOB field. If you have the rich text in a TRichEdit, you can
    stream it to a TppRichText object as well.

    ----------------------------------------------------------
    Tech Tip: Assigning Font Attributes of RichText component
    ----------------------------------------------------------

    You can assign font attributes to a RichText component
    by using the SelStart, SelLength properties or the
    the SelectAll method to select the text. Then assign
    the font to the RichText.SelAttributes property.

    Example:

    var
    lFont: TFont;

    begin

    lFont := TFont.Create;
    lFont.Name := 'Arial';
    lFont.Size := 14;
    lFont.Color := clRed;
    lFont.Style := [fsItalic, fsBold];

    ppRichText1.SelectAll;
    ppRichText1.SelAttributes.Assign(lFont);

    end;



    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com

    ------------------------------------------------
    Tech Tip: Copy RTF data from TRichEd to TppRichText
    ------------------------------------------------

    You can copy RTF data from Delphi's TRichEd to ReportBuilder's TppRichText
    control by using an intermediate memory stream:



    var
    lRTFStream: TMemoryStream;

    begin

    {create temp memory stream}
    lRTFStream := TMemoryStream.Create;

    {save the TRichEd's rtf data to the memory stream}
    RichEdit1.Lines.SaveToStream(lRTFStream);

    {load the rtf stream to the TppRichText}
    lRTFStream.position := 0;
    ppRichText1.LoadFromRTFStream(lRTFStream);

    {free the memory stream}
    lRTFStream.Free;


    end;


    Note: An alternative method would be to use RichEdit1.Lines.SaveToFile and
    TppRichText.LoadFromFile.



    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    Jim,

    Thanks so much for you help on this!
    John

This discussion has been closed.