Forum > LCL

Howto: HTML Tags around Selection in Memo


Explanation needed:

I have a toolbar with bold, italic, underline etc buttons on it. The aim is to format selected text with HTML tags.


<b>some text</b>

I know I should be using SelLength and SelStart, but what do I do to actually insert the text before and after my selection?

Maybe you can work together with this one  :)

Something like this:

--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
var s: string;
  s := Memo1.Lines.Text;
  system.Insert('</b>', s, memo1.SelStart + memo1.SelLength+1);
  system.Insert('<b>',  s, memo1.SelStart+1);
  Memo1.Lines.Text := s;

--- End code ---

Thank you once again eny. Any Caveats you can think of?

You're welcome  8)

No real caveats here. It's a brute force solution that works.
Make sure to use ansi strings during compilation (else 's: string' is limited to 255 chars).
You could test for 'SelLength > 0', although the application doesn't crash if you don't.
It just inserts two adjacent tags (like '<i></i>').


[0] Message Index

Go to full version