Page 1 of 1

TDBRichviewEdit new color style

Posted: Sun Jan 11, 2015 5:30 pm
by jota
Hi

In an empty TDBRichviewEdit i click on a button for change color style, but when i write, the characters appears in default color style.

If after writting i click on color style button other time, the next characters i write appears in the new color style.

Why occurs this behaviour? How i can do so that is written from the first character with the new color style?.

Can anyone help?.

Thanks in advance.

Posted: Mon Jan 12, 2015 3:49 pm
by Sergey Tkachenko
Right click TDBRichViewEdit at designtime, choose "Settings" in the context menu.
Select "Allow adding styles dynamically" and press OK.

Posted: Mon Jan 12, 2015 8:47 pm
by jota
Hello

"Allow adding styles dynamically" was already selected.

I can add the new style, but only after having written some character in the TDBRichviewEdit (If this is empty does not work)

Is there a property, configuration, etc. that causes this behavior?

Thanks

Posted: Tue Jan 13, 2015 6:35 am
by Sergey Tkachenko
When the table is changed to an editing state, the editor may reload data from the database. In this case, all changes to styles will be lost, because they will be replaced to styles loaded from the database.

Normally, it does not happen, because the recommended way to apply text or paragraph changes, such as color, is doing it inside OnStyleConversion/OnParaStyleConversion. These events are called from ApplyStyleConversion/ApplyParaStyleConversion, when the editor is ready to accept changes.

However, it may be a problem when you use ApplyTextStyle, ApplyParaStyle, or ApplyListStyles. These methods assume that you add a new style before their execution.
To solve the problem, call editor.CanChange before the operation:

Code: Select all

if dbrve.CanChange then begin
  <add new style here>
  dbrve.ApplyTextStyle(...)
end;