AddTextNL with Style Template
Posted: Fri May 31, 2013 7:38 am
Hello
I like the new feature of the style templates in RichView 14.
But I have some understanding problems how the style templates and the textstyles are connected.
As an example, how can I add a text and set a proper style template?
Have I to use the StyleTemplateId-property?
One of many attempts:
Thanks
RedOne
I like the new feature of the style templates in RichView 14.
But I have some understanding problems how the style templates and the textstyles are connected.
As an example, how can I add a text and set a proper style template?
Have I to use the StyleTemplateId-property?
One of many attempts:
Code: Select all
function FindTextStyleByName( AName: string ): TFontInfo;
var
i: Integer;
begin
for i:= 0 to rvEdit.Style.TextStyles.Count - 1 do begin
if SameText( rvEdit.Style.TextStyles.Items[ i ].StyleName, AName ) then begin
Result:= rvEdit.Style.TextStyles.Items[ i ];
exit;
end;
end;
end;
procedure AddText;
begin
rvEdit.Clear;
rvEdit.AddTextNL( 'Text without style', -1, -1, -1 );
FindTextStyleByName( 'heading 1' ).StyleTemplateId:= rvEdit.Style.StyleTemplates.FindItemByName( 'heading 1' ).Id;
rvEdit.AddTextNL( 'Text with style', FindTextStyleByName( 'heading 1' ).Index, -1, -1 );
// or with .ID?
rvEdit.AddTextNL( 'Text with style', FindTextStyleByName( 'heading 1' ).ID, -1, -1 );
end;
// Change a text style. This works fine
procedure TForm31.ButtonChangeStyleClick(Sender: TObject);
var
index: Integer;
frm: TfrmRVStyles;
tmpstyle: TRVStyle;
begin
tmpstyle := TRVStyle.Create(Self);
tmpstyle.StyleTemplates.AssignStyleTemplates( rvEdit.Style.StyleTemplates, true);
with tmpstyle.StyleTemplates.FindItemByName( 'heading 1' ) do
begin
TextStyle.Color := clRed;
ValidTextProperties := ValidTextProperties + [rvfiColor];
end;
rvEdit.ChangeStyleTemplates(tmpstyle.StyleTemplates);
rvEdit.RVData.PaintBuffered;
tmpstyle.free;
end;
RedOne