Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I insert text into a memo? 1

Status
Not open for further replies.

TimSNL

Programmer
Sep 11, 2001
119
AU
Hello.

I need to insert a string into a memo at the cursor position.
I can see how to do it using the clipboard, but I didn't want to upset anything the user may already have in the clipboard.
Is there another way to do this?

Thanks for your help.
Tim
SNL Computing
 
Tim,

Use something along these lines:

Code:
   Memo1.SelText := 'Text to Insert';

SelText will either replace the selected text with whatever you pass to it. If nothing is selected in the memo, then it adds the text at the insertion point.

You can control the insertion point by setting the SelStart property. Set it to 0 to move the insertion point to the beginning and to something along the lines of
Code:
IntToStr( length( Memo1.Text ) )
.

Hope this helps...

-- Lance
 
Gak!

That last paragraph should read:

"You can control the insertion point by setting the SelStart property. Set it to 0 to move the insertion point to the beginning and to something along the lines of
Code:
length( Memo1.Text )
to move the insertion point to the end."

Sorry for the bad typing (and/or editing, take your pick)...

-- Lance
 
index := Memo.ItemIndex;
Memo.Lines.Insert[index, strTextToInsert];

This should do it as well I think. Sometimes it is easier to work with the items property than the text property.
 
The seltext should have first go, as usually you'll be inserting when a user presses some button, and the cursor would be at SelPos, with some text selected for SelLength chars, and 0 being noting selected. If I press the 'Insert the smiley mnemonic' button, it would be nicely inserted at current cursor position ;-)

HTH
TonHu
 
Thankyou everyone [upsidedown].
You have helped me out.
Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top