Page 1 of 1

Insert text at the beginning of a TRichView

Posted: Sun Sep 22, 2019 12:23 pm
by Shouldercannon
Please tell me how to insert text at the beginning of a TRichView

Re: Insert text at the beginning of a TRichView

Posted: Mon Sep 23, 2019 7:31 am
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);