Page 1 of 1
Insert text at cursor position
Posted: Thu Oct 26, 2006 8:47 am
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?
Posted: Thu Oct 26, 2006 9:18 am
by Sergey Tkachenko
InsertText method (or PasteText, if from the Clipboard)
Posted: Thu Oct 26, 2006 11:40 am
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.
Posted: Fri Oct 27, 2006 2:12 pm
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)
Posted: Mon Oct 30, 2006 9:03 am
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;
Posted: Mon Oct 30, 2006 2:32 pm
by Sergey Tkachenko
j&b, is it a question?
Posted: Mon Oct 30, 2006 8:39 pm
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.