• I am trying to add styles support to our RTF Editor, based on TWPRichText. We can't use your own Style combobox, due to design differences, so I had to implement our own. And I am experiencing problems.
    My control is simple, I am offering user a set of 7 predefined styles, without ability to rename them, add new, etc.
    At the start I create this style list using a code like this:

    Code
    sty: TWPTextStyle;  ...  Editor.ParStyles.Clear;  for i := Low(FStyles) to High(FStyles) do  begin    sty := Editor.ParStyles.AddStyle(FStyles[i].Name);    sty.ASetFontName(FStyles[i].FontName);    sty.ASet(WPAT_CharFontSize, 100 * FStyles[i].FontSize);    if FStyles[i].Bold then        sty.ASetAddCharStyle(WPSTY_BOLD);    ...  end;


    Then I am trying to set a default style to one of them with

    Code
    Editor.CurrAttr.StyleName := NORMAL_STYLE;


    When user selects a style via combobox I run this code:

    Code
    Editor.CurrAttr.StyleName := StyleNameCombobox.Text;
      EditorCharacterAttrChange(Self, nil);  // to show font name, size, etc.
      Editor.ReformatAll(true);
      Editor.Repaint;


    I also have separate combos for Font name, size and color which worked fine from before.
    It works very erratic, with styles getting lost.
    What would you recommend?

    Also, when user starts a new paragraph (pressing Enter), current style always gets lost and reverted to <default attributes>, in your demos as well. Is it possible for a new paragraph to always get assigned a particular style, e.g. 'Normal'?

    Aleksandar Momcilovic,
    Maestro Soft, Norway

    • Offizieller Beitrag

    Aou can assign a style also to a paragraph: ABasestyle

    But you will not see effects which have been overridden by the text itself.

    USe RichText.ActiveStyleName

    and add wpClearAttrOnStyleChange to EditOptions

    Julian

  • Thanks Julian,
    I found out that disappearing styles was caused by RichText.Clear prior to LoadFromFile and I learned that I could use ClearEx(True, False, False) instead to preserve them.

    The 2nd question was about a default new paragraph style - how could I set a certain (e.g. 'Normal') default style for every new paragraph, instead of reverting back to default attributes?