Page 1 of 1

Insert text formatted.

Posted: Tue Dec 17, 2013 5:05 pm
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.

Posted: Wed Dec 18, 2013 2:59 pm
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);

Posted: Wed Dec 18, 2013 5:18 pm
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

Posted: Thu Dec 19, 2013 8:01 am
by Sergey Tkachenko

Posted: Thu Dec 19, 2013 4:44 pm
by Ceprotec
thanks sergey