Insert text formatted.

General TRichView support forum. Please post your questions here
Post Reply
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Insert text formatted.

Post by Ceprotec »

Hello, I wonder how do I insert a word in the text already formatted, eg, centralized and blue.

I am using the following code:

Code: Select all

SRichViewEdit1.RichViewEdit.InsertText('Mario da Silva',false);
but not places with no formatting.
Can you help me?
Thanks.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Text color (blue) is a text attribute (property of an item in RVStyle.TextStyles).
Alignment (centered) is a paragraph attribute (property of an item in RVStyle.ParaStyles).

You can define text attributes for new text by assigning RichViewEdit.CurTextStyleNo.
As for changing a paragraph attribute, use ApplyParaStyle. But of course, it affects all text in the current paragraph.

Code: Select all

// returns an index of a text style having the same properties
// as the current text style, but the specified color
// (searching for an existing style; if not found, adding a new style)
function GetColoredTextStyleNo(rve: TCustomRichViewEdit; Color: TColor): Integer;
var TextStyle: TFontInfo;
begin
  TextStyle := TFontInfo.Create(nil);
  TextStyle.Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
  TextStyle.Color := Color;
  Result := rve.Style.FindTextStyle(TextStyle);
  TextStyle.Free;
end;

// returns an index of a paragraph style having the same properties
// as the current paragraph style, but the specified alignment
// (searching for an existing style; if not found, adding a new style)
function GetAlignedParaNo(rve: TCustomRichViewEdit; Align: TRVAlignment): Integer;
var ParaStyle: TParaInfo;
begin
  ParaStyle := TParaInfo.Create(nil);
  ParaStyle.Assign(rve.Style.ParaStyles[rve.CurParaStyleNo]);
  ParaStyle.Alignment := Align;
  Result := rve.Style.FindParaStyle(ParaStyle);
  ParaStyle.Free;
end;

// Using:
SRichViewEdit1.ActiveEditor.ApplyParaStyle(GetAlignedParaNo(SRichViewEdit1.ActiveEditor));
SRichViewEdit1.ActiveEditor.CurTextStyleNo := GetColoredTextStyleNo(SRichViewEdit1.ActiveEditor);
SRichViewEdit1.ActiveEditor.InsertText('Mario da Silva',false);
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

ok, I have a function called

Code: Select all

procedure GoToLine (LineNo: Integer; rve: TCustomRichViewEdit)

but would have something to pages, something like GoToPage?

thanks sergey
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

thanks sergey
Post Reply