Posted: Thu Aug 12, 2010 12:11 pm
In TRichView, code will be completely different.
As I understand, you need to create a new document.
In this case, create a set of text and paragraph styles used in your document, then use their indices when adding text.
A set of styles can be created one time, before the first document generation.
As you can see, after all styles are created, a code for generating document is very simple.
Moreover, if you modify properties of styles
(for example, assign RVStyle1.TextStyles[TEXT_HEADER1].Color := clBlue), your document will be changed automatically.
As I understand, you need to create a new document.
In this case, create a set of text and paragraph styles used in your document, then use their indices when adding text.
Code: Select all
const TEXT_NORMAL = 0;
TEXT_HEADER1 = 1;
TEXT_HEADER2 = 2;
PARA_NORMAL = 0;
PARA_HEADER1 = 1;
PARA_HEADER2 = 2;
procedure InitStyles(RVStyle1: TRVStyle);
begin
RVStyle1.TextStyles.Clear;
// creating a style for normal text TEXT_NORMAL
RVStyle1.TextStyles.Add;
// creating a style for heading level 1 TEXT_HEADER1
with RVStyle1.TextStyles.Add do begin
Style := [fsBold, fsUnderline];
StyleEx := [rvfsAllCaps];
end;
// creating a style for heading level 2 TEXT_HEADER2
with RVStyle1.TextStyles.Add do begin
Style := [fsBold];
end;
RVStyle1.ParaStyles.Clear;
// creating a style for normal paragraph PARA_NORMAL
RVStyle1.ParaStyles.Add;
// creating a style for heading level 1 paragraph TEXT_HEADER1
with RVStyle1.ParaStyles.Add do begin
OutlineLevel := 1;
FirstIndent := 5;
end;
// creating a style for heading level 2 paragraph TEXT_HEADER2
with RVStyle1.ParaStyles.Add do begin
OutlineLevel := 2;
Alignment := rvaRight;
end;
end;
procedure BuildDoc(rv: TCustomRichView);
begin
rv.Clear;
rv.AddNL('Review of Systems', TEXT_HEADER1, PARA_HEADER1);
rv.AddNL('eyes, ear, nose', TEXT_HEADER2, PARA_HEADER2);
rv.AddTextNL('blah blah blah blah'#13'blah blah blah blah',
TEXT_NORMAL, PARA_NORMAL, PARA_NORMAL);
rv.Format;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InitStyles(RVStyle1);
BuildDoc(RichViewEdit1);
end;
As you can see, after all styles are created, a code for generating document is very simple.
Moreover, if you modify properties of styles
(for example, assign RVStyle1.TextStyles[TEXT_HEADER1].Color := clBlue), your document will be changed automatically.