Insert text at cursor position

General TRichView support forum. Please post your questions here
Post Reply
Dmitry Kholl
Posts: 5
Joined: Thu Oct 26, 2006 8:28 am

Insert text at cursor position

Post by Dmitry Kholl »

I need to paste some text at cursor position and the cursor should be placed at the end of the placed text. Please explain how i can do it?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

InsertText method (or PasteText, if from the Clipboard)
Dmitry Kholl
Posts: 5
Joined: Thu Oct 26, 2006 8:28 am

Post by Dmitry Kholl »

Is there any way to set cursor position?
When I insert text at TRichViewEdit it isn't focused.

And after InsetText I call SetFocus for TRichViewEdit. The cursor is at the begining. But I need after the inserted text.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

InsertText moves caret to the end of the inserted text (or to the beginning, depending on the last (optional) parameter.
May be you call Format after InsertText? It's not needed, and moves caret to the beginning.

Caret is moved by SetSelectionBounds method (set the both bounds to the same values to move caret without making selection)
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

procedure TForm1.Button1Click(Sender: TObject);
//var remember: string; ---> PRIVATE
begin
(*
a)
clipboard.clear;
if Memo.SelectionExists=false then memo.selectCurrentLine;
memo.CopyDef;
Memo.Deselect;
*)
// b)
remember:= 'Hello Paul';
end;

procedure TForm1.Button2Click(Sender: TObject);
// only for b)
var s, leer, strich: string;
itemNo, offs: integer;
//end of only for b)
begin
(*
a)
memo.SetFocus;
Memo.paste;
*)

// b)
memo.setfocus;
//ItemNo := memo.ItemCount-1; Offs := memo.GetOffsAfterItem(ItemNo);
//memo.SetSelectionBounds(ItemNo, Offs, ItemNo, Offs); //at the end of memo
Memo.insertText(remember,false);
end;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

j&b, is it a question?
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

No, an example with 2 solutions:
a) if you want to use clipboard
b) if you want to set a string at the position of caret.
Post Reply