DefaultAttr and ParagraphStyles

  • Hello,

    I have a problem with ParagraphStyles and the DefaultAttr.

    I create two ParapgraphStyles like this:

    Code
    Style:=RichText.ParStyles.AddStyle('MSGTITLE');Style.ASetAddCharStyle(WPSTY_BOLD);Style:=RichText.ParStyles.AddStyle('MSGTEXT');Style.ASetDelCharStyle(WPSTY_BOLD);


    Both should be derived from the DefaultAttr.

    At first this seems to work. I'm using this code to add paragraphs to the rtf control:

    Code
    if RichText.IsEmpty then Par:=RichText.LastPar
    else Par:=RichText.LastPar.AppendNewPar;
    Par.ABaseStyleName:='MSGTITLE';
    Par.SetText('['+Time2Str(TimeGetTime)+'] '+Match+':');
    
    
    Par:=Par.AppendNewPar;
    Par.ABaseStyleName:='MSGTEXT';
    RichText.CPPosition:=MaxInt;
    RichText.SelectionAsString:=Msg;


    The variable Msg can be RTF-Text. If this is the case and the font differs from the DefaultAttr, then the next time I add a new paragraph, the Style MSGTITLE isn't derived from DefaultAttr anymore, but from this new font style.

    So my question is:
    Can I add a new ParagraphStyle as a real copy of the DefaultAttr?
    Or is it possible to set the font back to DefaultAttr after SelectionAsString:=Msg?

    Regards,
    Björn

    • Offizieller Beitrag

    Hi,

    DefaultAttr is just an interface to the default font, color and style. It is not a paragraph style.

    Text which does not use any special attributes (font, color, style) uses the one from DefaultAttr - unless there is a paragraph style or attributes in the paragraphs which can be used.

    To make sure the text does not use chareacter attributes it is possible to call

    TParagraph.ClearCharAttr - this will set the CharAttr references to 0.

    You can also do this for the selected text

    WPRichText1.SelectedTextAttr.ClearAttr(false, true);

    So you need to select the text after it was inserted (store CPPosition and use SetSelPosLen)