Page 1 of 1

TDBRichViewEdit: default font and size in new record

Posted: Sun Mar 18, 2012 1:54 pm
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

Posted: Sun Mar 18, 2012 6:40 pm
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.

Posted: Mon Mar 19, 2012 12:40 pm
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