Beiträge von AleksandarMaestro

    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?

    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

    I tried this code in EditorBeforePasteText event handler:

    I got mixed results. Styles are finally gone and resulting text resembles the original one. The problem is that when content is saved and reloaded it looks different than on the screen (font and size usually).
    How could I improve from here?

    My application is not supporting paragraph styles and it always creates us problems when someone pastes text from e.g. Word that uses them. Text will be properly displayed in TWPRichText, but it won't be possible to remove bold, italics, e.g.

    I am trying to remove styles in BeforePasteText event, but to replace them with appropriate attributes, for text to look the same.
    It is easy to remove styles with par.Style := 0, but I am not sure what would be the best way to implement that style attributes to the whole paragraph.
    Any suggestions?