Word Insert at Cursor
Posted: Sat Sep 14, 2019 11:59 am
Hi,
I have a User Interface, where there is a SRichViewEdit and a StringGrid with a single column. When the user double clicks on an item in stringgird, the data in the column gets populated in the SRichViewEdit. The thing is , how to insert this word from stringgrid at the Cursor, How to to set the font ,color styles and, then move the cursor to next line.
I used modified \TRichView\ScaleRichView\Demos\ActionTest\ActionTest demo and built on that, I am not that familiar with other details.
I use the following code to place the text
InitialAssessment.RichViewEdit.InsertText(MainData.Cells[0,MainData.Row], False);
For my requirement I tried the following code from an earlier post. But I could not get that to work , since it was very old and the parameters are diferent now.
I know it simple. Early help is highly appreciated. Thanks in advance
This one
// 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);
I have a User Interface, where there is a SRichViewEdit and a StringGrid with a single column. When the user double clicks on an item in stringgird, the data in the column gets populated in the SRichViewEdit. The thing is , how to insert this word from stringgrid at the Cursor, How to to set the font ,color styles and, then move the cursor to next line.
I used modified \TRichView\ScaleRichView\Demos\ActionTest\ActionTest demo and built on that, I am not that familiar with other details.
I use the following code to place the text
InitialAssessment.RichViewEdit.InsertText(MainData.Cells[0,MainData.Row], False);
For my requirement I tried the following code from an earlier post. But I could not get that to work , since it was very old and the parameters are diferent now.
I know it simple. Early help is highly appreciated. Thanks in advance
This one
// 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);