Forum > LCL
Howto: HTML Tags around Selection in Memo
(1/1)
commodianus:
Explanation needed:
I have a toolbar with bold, italic, underline etc buttons on it. The aim is to format selected text with HTML tags.
e.g.
<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?
eny:
Maybe you can work together with this one :)
Something like this:
--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
var s: string;
begin
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;
--- End code ---
commodianus:
Thank you once again eny. Any Caveats you can think of?
eny:
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>').
Navigation
[0] Message Index