Replacing RichEdit

General TRichView support forum. Please post your questions here
Post Reply
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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.

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;
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.
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As I understand, headings are always inserted above the current paragraphs, and plain text is always inserted at the end of the document.
Here is my example:
http://www.trichview.com/support/files/ ... Sample.zip
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

All Insert* methods of TRichViewEdit, including InsertText (used in my example) insert new content in the position of caret.
In my demo, I used additional code to move the caret to the beginning of the paragraph or to the end of the document before the insertion.

So, if you want to insert the sting S in the position of the caret, just call

Code: Select all

RichViewEdit1.InsertText(S);
If you want to define font for this string, call ApplyTextStyle before, like this:

Code: Select all

RichViewEdit1.ApplyTextStyle(TEXT_NORMAL);
RichViewEdit1.InsertText(S);
Post Reply