Insert text at the beginning of a TRichView

General TRichView support forum. Please post your questions here
Post Reply
Shouldercannon
Posts: 4
Joined: Sat Sep 21, 2019 1:35 pm

Insert text at the beginning of a TRichView

Post by Shouldercannon »

Please tell me how to insert text at the beginning of a TRichView
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Insert text at the beginning of a TRichView

Post by Sergey Tkachenko »

While TRichViewEdit has methods for insertion at the caret position, TRichView has only methods for adding to the end. The only exception is InsertRVFFromStream.
However, you can use the function from RVInsertItems.pas:

Code: Select all

procedure RVInsertString(RVData: TCustomRVData; ItemNo: Integer;
  const s: String; StyleNo, ParaNo: Integer; const Tag: TRVTag = RVEMPTYTAG);
To insert at the beginning, the parameter ItemNo must be 0, like:

Code: Select all

RVInsertString(RichView1.RVData, 0, 'Hello world!', 0, 0);
RichView1.Format;
Please be careful when using this method, it may create an incorrect document when used incorrectly, see https://www.trichview.com/help/valid_documents.html

PS: this unit also has a method for inserting a picture:

Code: Select all

procedure RVInsertGraphic(RVData: TCustomRVData; ItemNo: Integer;
  Graphic: TGraphic; Hyperlink: Boolean; ParaNo: Integer;
  VAlign: TRVVAlign = rvvaBaseline; const Tag: TRVTag = RVEMPTYTAG);
Post Reply