2 Simple Memo Quoestions

Hi,

How could I place the cursor in the middle after I insert the text ? Let`s say I insert <a></a> and I want the cursor between the tags.

Also if u can tell me how should I do when I press enter in the memo to replace add <br> before the new line ...

Thanks
crystyanAsked:
Who is Participating?
 
2266180Commented:
1) use the SelStart property. you will have to calculate the exact pozition according to your needs (I would guess that <a></a> will not be the only text in the memo ;)

2) use the onkeypress event:
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var i:integer;
begin
  if key=#13 then
  begin
    i:=memo1.SelStart;
    memo1.text:=copy(memo1.text,1,i)+'<br>'+copy(memo1.text,i+1,length(memo1.text));
    memo1.SelStart:=i+4;;
  end;
end;

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.