Sorry my english!
I use InsertText for insert one word in RichViewText, I need insert in different color in text. How i make this?
Thanks.
Please is possible one example? I'm beginner user.
InsertText in different color of the text in richview
-
- Posts: 13
- Joined: Tue Feb 06, 2007 2:48 pm
- Location: Cambui, Brazil
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Code: Select all
function GetTextStyleWithColor(rve: TCustomRichViewEdit; Color: TColor): Integer;
var BackColor: TColor;
begin
BackColor := rve.Style.TextStyles[rve.CurTextStyleNo].BackColor;
Result := rve.Style.TextStyles.FindStyleWithColor(rve.CurTextStyleNo,
Color, BackColor);
if Result<0 then begin
// the style is not found, creating it
rve.Style.TextStyles.Add;
Result := rve.Style.TextStyles.Count-1;
rve.Style.TextStyles[Result].Assign(rve.Style.TextStyles[rve.CurTextStyleNo]);
rve.Style.TextStyles[Result].Color := Color;
rve.Style.TextStyles[Result].Standard := False;
end;
end;
procedure InsertColoredText(rve: TCustomRichViewEdit; const Text: String; Color: TColor);
var StyleNo: Integer;
begin
StyleNo := rve.CurTextStyleNo;
rve.CurTextStyleNo := GetTextStyleWithColor(rve, Color);
rve.InsertText(Text);
rve.CurTextStyleNo := StyleNo;
end;
The code above uses FindStyleWithColor function. It allows finding text style with the given text and background color. The most universal style searching function is FindSuchStyle. Search "FindSuchStyle" in this forum for examples.
-
- Posts: 13
- Joined: Tue Feb 06, 2007 2:48 pm
- Location: Cambui, Brazil
InsertColorText
Thanks very much!
I test the function in RichViewEdit, is perfect, insert into cursor position and search and replace, the function is all right.
But, using in DBRichViewEdit, a error ocurred: 'List index out of bounds', for DBRichViewEdit the function is different?
I test the function in RichViewEdit, is perfect, insert into cursor position and search and replace, the function is all right.
But, using in DBRichViewEdit, a error ocurred: 'List index out of bounds', for DBRichViewEdit the function is different?
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Posts: 13
- Joined: Tue Feb 06, 2007 2:48 pm
- Location: Cambui, Brazil
I think that found the problem
I'm using DBRichView and DBRichViewEdit in form with same RVStyle for both. This cause an error.
With one RVStyle for each, the function run correctly.
The manner to use DBRichView, DBRichViewEdit, RichView and RichViewEdit is with one RVStyle for each? This is correct?
Thanks, for help.
With one RVStyle for each, the function run correctly.
The manner to use DBRichView, DBRichViewEdit, RichView and RichViewEdit is with one RVStyle for each? This is correct?
Thanks, for help.