TDBRichViewEdit: default font and size in new record

General TRichView support forum. Please post your questions here
Post Reply
Joe
Posts: 28
Joined: Tue Feb 14, 2012 6:15 am

TDBRichViewEdit: default font and size in new record

Post by Joe »

Hello,

I have a TDBRichViewEdit control on a form, bound to a field in a database. There is also a RVStyle object bound to the TDBRichViewEdit field. In the RVStyle object the default styles are stored (I have made no modification there). In addition, there are several toolbars for text formatting (copied with all events from the ActionText2007 example).

When a record is edited all text formatting can be done in the TDBRichViewEdit field and saved and reloaded successfully. When a record is loaded and edited again, the Font and FontSize comboboxes in the toolbar show the correct font and size relative to the text where the focus moves - everything fine.

But when creating a new record the Font and FontSize comboboxes are initially blank (no font name is shown, and no font size is shown). I can edit text and the text is initially formatted to Arial 10 (as in the standard style in the RVStyle object). This is good - but how can I show the current font and font size in a brand new record?

Joe
Sergey Tkachenko
Site Admin
Posts: 17561
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use OnNewDocument event.
In this event, you can set the default text and paragraph styles, for example:

Code: Select all

RVStyle1.TextStyles.Clear;
with RVStyle1.TextStyles.Add do begin
  FontName := 'Arial';
  FontSize := 10;
end;
RVStyle1.ParaStyles.Clear;
RVStyle1.ParaStyles.Add;
RVStyle1.ListStyles.Clear;
DBRichViewEdit1.OnCurTextStyleChange(DBRichViewEdit1);
The last line must update combo boxes (if they are updated inside this event. However, it is strange that they are not updated automatically. I'll test tomorrow.
Joe
Posts: 28
Joined: Tue Feb 14, 2012 6:15 am

Post by Joe »

Hello Sergey,

thank you for your response. In the OnShow() event of the form, after the underlying dataset has been initialized to a new record, I now call the OnCurTextStyleChange().

And this works. Great!

Thank you!
Joe
Post Reply