I can use IpHtmlPanel2.SetHtmlFromStr() to set the HTML Text of the control.
But how can I add a single line to an existing text?
Or is the TIpHtmlPanel not the right component to dynamically add text?
You must store the string to be displayed outside the HTML panel and add the new line to it. Then you put this into the SetHtmlFromStr again.
But there are several issues:
- Using a "mini-browser" like IpHtmlPanel just for displaying some red words here and there looks like overkill to me.
- The IpHtmlPanel adds some margin at the top and bottom of each paragraph which makes the lines look too much apart. I don't know how to turn this off, css margin does not seem to work here.
- And there does not seem to be a way to autoscroll the panel when a line is added.
Therefore, I played with the TJvHTLabel which belongs to the JVCL library and can display a very simple html, but just enough to change the font and font color. Having its AutoSize set to true and putting it into a TScrollbox you can achieve also autoscrolling to the end of the list.
Just look at the attached demo.
The easiest way to get TJvHTLabel is to use Online Package Manager: Scroll down to the JVCLLaz packages and check the package JvCtrlsLazD (only this one if you don't need the others; note the "D" at the end, for "design-time package"!). Click Install and confirm the questions to resolve dependencies (i.e. the JVCL packages on which JvCtrlsLazD depends will be installed, too).
All the html solutions have the disadvantage that
- the storage string will have to be copied to another location when another message is added.
- the html string will have to be re-parsed every time a new message is added.
Both points will have an effect on speed, in particular if there are "many" messages. If speed becomes an issue you should write your own LogMessageViewer which should use more clever storage and should paint and parse the color codes only for the visible lines.