Memo Component that supports HTML markup lazarus / 31-LCL ---------------------------------------------------------------------- Tony Stone · 2021-08-23 23:39 I am trying to find a component that is very similar to a memo.  I would like to be able to add lines with HTML markup.  Mostly just to add color, bold etc.  The simple things.  The HTML components I am finding seem very heavy and complex.  I can't help but to think there must be a simple memo that renders very basic HTML markup.  A rich text memo looks like it may be what I need to go with however it just seems like it will be a lot of code to set multiple colors on a single line of text after editing it.  Anyone know of anything out there that may suite me? My end users will be mostly Windows and Linux. ---------------------------------------------------------------------- Tony Stone · 2021-08-23 23:57 Yeah, I am just looking to display some log files.  And i currently make a synedit scroll down everytime a line is added.  That seems to be an issue with the current HTML components. I am playing with a RichMemo right now.  Is it possible to add raw RTF code as a string and have it formatted?  I am trying to do that now but not really working out. lol. By the way.... you are very missed on IRC ---------------------------------------------------------------------- Tony Stone · 2021-08-24 00:13 Quote from: jamie on August 24, 2021, 01:50:13 amLook on the IPro tab Edit:  I mean it will display HTML in basic form..  don't expect a lot from it, its more for displaying etc.. Hey!  I have a partially implemented example of what I am trying to do using TlpHtmlPanel  I am not so sure I am able to make it scroll yet.  So far though... I think this may be the solution I was looking for. ---------------------------------------------------------------------- skalogryz · 2021-08-24 04:18 Quote from: Tony Stone on August 24, 2021, 01:39:17 amMy end users will be mostly Windows and Linux. Qt5 Memo should be capable of that. But you'll need to make low-level Q5 access. ---------------------------------------------------------------------- avra · 2021-08-24 06:23 Quote from: Tony Stone on August 24, 2021, 01:57:51 amI am playing with a RichMemo right now.  Is it possible to add raw RTF code as a string and have it formatted?Wiki has some examples: https://wiki.freepascal.org/RichMemo#Append_mixed_color_text_at_the_en d_of_the_RichMemo https://wiki.freepascal.org/RichMemo#SetTextAttributes ---------------------------------------------------------------------- wp · 2021-08-24 11:19 Quote from: Tony Stone on August 24, 2021, 01:57:51 amI am just looking to display some log files. In this case possibly the HTML components in the JVCL are enough for you: - TJvMarkupLabel: displays HTML text with simple formatting instructions, suitable for multi-line text - TJvMarkupViewer: similar to MarkupLabel, but displays a vertical scrollbar - TJvHTLabel: a single-line label, probably not what you need. You do not need to install the entire JVCL to get these components, JvJans is enought. In OPM, select the items jvjanslazr.lpk and jvjanslazd.r under the JVCLLaz node, then install. Usage is self-explaining but here is the code which I just tested. Note that line-breaks must be triggered by inserting '
'; the constant LineEnding is not respected. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);const  LoremIpsum: string =    'Lorem ipsum dolor sit amet, '+    'consetetur sadipscing elitr, sed diam nonumy eirmod tempor '+    '
'+    'invidunt ut labore et dolore magna aliquyam erat, '+    '
sed diam voluptua. '+    '
'+    'At vero eos et accusam et justo duo dolores et ea rebum. '+    '
'+    'Stet clita kasd gubergren, no sea '+    '
' +                  // Linebreak does not work.    'takimata sanctus est Lorem ipsum dolor sit amet.';begin  JvMarkupViewer1.Text :='JvMarkupViewer:
' +  LoremIpsum;  JvMarkupLabel1.Text := 'JvMarkupLabel:
' + LoremIpsum;end; ---------------------------------------------------------------------- Tony Stone · 2021-08-24 12:09 Quote from: wp on August 24, 2021, 01:19:04 pmQuote from: Tony Stone on August 24, 2021, 01:57:51 amI am just looking to display some log files. In this case possibly the HTML components in the JVCL are enough for you: - TJvMarkupLabel: displays HTML text with simple formatting instructions, suitable for multi-line text - TJvMarkupViewer: similar to MarkupLabel, but displays a vertical scrollbar - TJvHTLabel: a single-line label, probably not what you need. You do not need to install the entire JVCL to get these components, JvJans is enought. In OPM, select the items jvjanslazr.lpk and jvjanslazd.r under the JVCLLaz node, then install. Usage is self-explaining but here is the code which I just tested. Note that line-breaks must be triggered by inserting '
'; the constant LineEnding is not respected. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);const  LoremIpsum: string =    'Lorem ipsum dolor sit amet, '+    'consetetur sadipscing elitr, sed diam nonumy eirmod tempor '+    '
'+    'invidunt ut labore et dolore magna aliquyam erat, '+    '
sed diam voluptua. '+    '
'+    'At vero eos et accusam et justo duo dolores et ea rebum. '+    '
'+    'Stet clita kasd gubergren, no sea '+    '
' +                  // Linebreak does not work.    'takimata sanctus est Lorem ipsum dolor sit amet.';begin  JvMarkupViewer1.Text :='JvMarkupViewer:
' +  LoremIpsum;  JvMarkupLabel1.Text := 'JvMarkupLabel:
' + LoremIpsum;end; Ok great.  Will look into this next time I get to play on my computer!  I did get the tihtmlpanel from ipro working that Jamie had suggested but the problem I was having is every time I added a new line it had to reload all of the text.  It became very messy when there was several hundred lines in my log.  Hopefully the JVCL component is a little more.optimized.  I will also need to save the text to a file when the user exits.  Hopefully it has a save to file procedure built in.  I suppose it wouldn't be that difficult to write a function myself to do that.  I will report back when I test it out. ---------------------------------------------------------------------- Tony Stone · 2021-08-24 12:12 Quote from: skalogryz on August 24, 2021, 06:18:10 amQuote from: Tony Stone on August 24, 2021, 01:39:17 amMy end users will be mostly Windows and Linux. Qt5 Memo should be capable of that. But you'll need to make low-level Q5 access. This is good to know.  However I am trying to keep my application light and for now I am using GTK2.  And that would require my end user to have QT installed I think.  And really... Anything low level is a little beyond my current skill-set.  In near future I would like to tackle this suggestion though... At the very least as an exercise. Thanks for your suggestion! ---------------------------------------------------------------------- wp · 2021-08-24 14:08 Quote from: Tony Stone on August 24, 2021, 02:09:28 pmbut the problem I was having is every time I added a new line it had to reload all of the text. Well, this will happen with the jvcl html components as well. But you can use the html utility functions of jvcl and, for example, custom-draw a list box. I did this in the attached project. A timer creates some dummy log messages (time plus some process status), and the message string is added to a listbox. The messages contain html code to highlight portions of the text. The listbox items are owner drawn using the jvcl html utility code - this is in unit JvJVCLUtils of the JvCore package, but I copied the related code into a separate unit (jvclHTMLUtils), therefore you do not need to install any JVCL package at all. The code to ownerdraw the listbox items is just in a few lines: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;  ARect: TRect; State: TOwnerDrawState);var  listbox: TListBox;begin  listbox := Control as TListbox;  if ([odSelected, odFocused] * State <> []) then  begin    listbox.Canvas.Brush.Color := RGBToColor(166, 202, 240);    listbox.Canvas.Font.Color := clHighlightText;  end else  begin    listbox.Canvas.Brush.Color := clWindow;    listbox.canvas.Font.Color := clWindowText;  end;  listbox.Canvas.FillRect(ARect);  HTMLDrawText(listbox.Canvas, ARect, [], listbox.Items[Index], 0.7, 100);  // <--- from JVCLend; So need for a separate component this way! ---------------------------------------------------------------------- Tony Stone · 2021-08-24 16:57 Quote from: wp on August 24, 2021, 04:08:15 pmQuote from: Tony Stone on August 24, 2021, 02:09:28 pmbut the problem I was having is every time I added a new line it had to reload all of the text. Well, this will happen with the jvcl html components as well. But you can use the html utility functions of jvcl and, for example, custom-draw a list box. I did this in the attached project. A timer creates some dummy log messages (time plus some process status), and the message string is added to a listbox. The messages contain html code to highlight portions of the text. The listbox items are owner drawn using the jvcl html utility code - this is in unit JvJVCLUtils of the JvCore package, but I copied the related code into a separate unit (jvclHTMLUtils), therefore you do not need to install any JVCL package at all. The code to ownerdraw the listbox items is just in a few lines: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;  ARect: TRect; State: TOwnerDrawState);var  listbox: TListBox;begin  listbox := Control as TListbox;  if ([odSelected, odFocused] * State <> []) then  begin    listbox.Canvas.Brush.Color := RGBToColor(166, 202, 240);    listbox.Canvas.Font.Color := clHighlightText;  end else  begin    listbox.Canvas.Brush.Color := clWindow;    listbox.canvas.Font.Color := clWindowText;  end;  listbox.Canvas.FillRect(ARect);  HTMLDrawText(listbox.Canvas, ARect, [], listbox.Items[Index], 0.7, 100);  // <--- from JVCLend; So need for a separate component this way! Uhm... WOW!  Thank you!  I am gonna play with your example and try to understand it all!  I didn't expect someone to put this much effort into my question!    I wonder if this could be the basis for me learning to write my own component that is registered in the component toolbar and everything.  And i have not tried yet but looking through the code I think i may need to implement some other way to store the strings added to the list with the HTML formatting so it can be saved to a file and loaded next time app starts.  I actually wanted to store my logs with no HTML formatting in a plain text and also a file with the formatting!  So I think from what I see here i may be able to figure it all out myself with the work you provided!  Again thank you! This is for certain on my list of components to create and contribute.  I have been wanting a simple memo-like component and listbox that supports HTML formatting... this really made my day seeing this. ---------------------------------------------------------------------- wp · 2021-08-24 18:03 Quote from: Tony Stone on August 24, 2021, 06:57:17 pmi may need to implement some other way to store the strings added to the list with the HTML formatting so it can be saved to a file and loaded next time app starts. Listbox1.Lines.SaveToFile(filename) saves the log items to file, and Listbox1.Lines.LoadFromFile(filename) reads them back. Quote from: Tony Stone on August 24, 2021, 06:57:17 pmI actually wanted to store my logs with no HTML formatting in a plain text and also a file with the formatting! When the logs have a well-defined structure you can handle them as plain text. Then when the strings are displayed in the OnDrawItem event of the listbox you analyze the string to be displayed (Listbox.Items[Index]) and insert html tags in a local variable. This variable can be passed to the HTMLDrawText procedure. After painting the local variable is discarded. This way you do not need to store the formatted texts. ---------------------------------------------------------------------- Tony Stone · 2021-08-25 03:45 Quote from: wp on August 24, 2021, 08:03:17 pmQuote from: Tony Stone on August 24, 2021, 06:57:17 pmi may need to implement some other way to store the strings added to the list with the HTML formatting so it can be saved to a file and loaded next time app starts. Listbox1.Lines.SaveToFile(filename) saves the log items to file, and Listbox1.Lines.LoadFromFile(filename) reads them back. Quote from: Tony Stone on August 24, 2021, 06:57:17 pmI actually wanted to store my logs with no HTML formatting in a plain text and also a file with the formatting! When the logs have a well-defined structure you can handle them as plain text. Then when the strings are displayed in the OnDrawItem event of the listbox you analyze the string to be displayed (Listbox.Items[Index]) and insert html tags in a local variable. This variable can be passed to the HTMLDrawText procedure. After painting the local variable is discarded. This way you do not need to store the formatted texts. So I made some modifications("improvements") to the example application you started.  I have a little polishing up to do on it and I am going to upload it here in hopes it is useful to someone else.  Last "feature" I am working on is a function to match text before adding it to a list based on a word list and changing its look.  Then I am gonna put comments that I think would be helpful to beginners like myself.  I am wondering if I can do the same thing with a memo as we did with the listbox.  I will try tomorrow. ---------------------------------------------------------------------- wp · 2021-08-25 08:15 Quote from: Tony Stone on August 25, 2021, 05:45:17 amI am wondering if I can do the same thing with a memo as we did with the listbox.  With the standard memo this is not possible because it does not allow to custom-paint the text. Maybe there's a more flexible third-party memo replacement out there, I don't know, but I don't think so. Why do you need a TMemo? To edit the log items? You could double-click on the listbox item and open an auxiliary form for editing. Or you could use a single-column TStringGrid instead of a TListbox which can be custom-painted as well and allows to in-place edit the cells (requires a bit more code, thoigh). ---------------------------------------------------------------------- Tony Stone · 2021-08-26 02:50 Well here it is.  I didn't add comments to it like I planned.  It is pretty simple.  I just thought comments from a beginner targeted to beginners could be useful.  But i stopped with my 'improvements' as I had a long day at my real job.  And i started running into issues with the floating edit if the form is resized.  I will try harder for my next Lazarus demo project.  Maybe the next one will be useful enough to include with the Lazarus examples! Thank you all!  LAZARUS IS THE BEST! (thanks developers) project1.zip https://www106.zippyshare.com/v/3Ond2L4f/file.html (project was too large to upload here, I will put it on one of my servers and update this post soon) ---------------------------------------------------------------------- Jurassic Pork · 2021-08-26 06:01 hello, Tony on a single monitor computer configuration, i don't see your form when i execute your project  : Top and Left properties of the form are too large : i can see your form if i reduce the values of those properties. Friendly, J.P ---------------------------------------------------------------------- Tony Stone · 2021-08-26 12:24 Grrr! I know this all too well when i open a project from my desktop system on my laptop.  Very annoying...  It is one thing I think Lazarus should be able to handle better.  My goal is to eventually add features and try to fix bugs with Lazarus.  I am just not there yet. I also think the Form Designer should show up in the Windows task bar and it just does not.  Makes it very annoying when using the form designer, specially if you are using the anchor package for the IDE.  I feel like there should be a drop down menu in the main Laz toolbar showing all form.  When a user selects it it should show up... and if it is off screen it should automatically bring it to the center of the active screen.  Those are some features I would like to add to the IDE. Anyway... I hope the demo program worked ok otherwise.  I am very impressed with the capabilities of Laz+FPC.  Something that simple amazes me for some reason. lol ---------------------------------------------------------------------- tetrastes · 2021-08-26 12:56 Quote from: Tony Stone on August 26, 2021, 02:24:34 pm I feel like there should be a drop down menu in the main Laz toolbar showing all form.  When a user selects it it should show up... and if it is off screen it should automatically bring it to the center of the active screen.  Those are some features I would like to add to the IDE. Isn't it enough? ---------------------------------------------------------------------- Tony Stone · 2021-08-26 13:34 Quote from: tetrastes on August 26, 2021, 02:56:10 pmQuote from: Tony Stone on August 26, 2021, 02:24:34 pm I feel like there should be a drop down menu in the main Laz toolbar showing all form.  When a user selects it it should show up... and if it is off screen it should automatically bring it to the center of the active screen.  Those are some features I would like to add to the IDE. Isn't it enough? Yes, it is actually enough.  Maybe I am being a bit Lazy... but menu's arent very quick.  Specially when i need to go through the View Forms dialog first.  Then center the lost window.  I know... it only takes 5 seconds... but still.  I feel like forms need to be very readily accessed from a drop down list, specially because Windows WILL NOT display it in the task bar.  So every time i want to change or select an item from the form i have to go to the dialog, then view form list...  its not the end of the world.  I just think it could use a small improvement. ---------------------------------------------------------------------- denis.totoliciu · 2021-08-26 21:49 Would be useful to activate the menu option Window -> Center lost window by using a key combination such as Ctrl+- and then each window that is listed in the menu to have a simple key assigned to it, such as 1, 2, 3, ... 9, A, B, ... Z. In this way the menu can be accessed quickly and also see the windows that can be accessed quickly for centering. The Window -> Center lost window is not listed in IDE Options -> Editor -> Key mappings. ---------------------------------------------------------------------- Tony Stone · 2021-08-29 21:56 http://www.stonemail.us/lazarus/htmlistbox.zip I said I wanted to make a demo work the way I wanted and comment it for new Lazarus programmers... well here it is. It works exactly the way I need for my program.  I hope this little project is useful for some one! ---------------------------------------------------------------------- avra · 2021-08-30 06:09 Quote from: Tony Stone on August 26, 2021, 03:34:23 pmI feel like forms need to be very readily accessed from a drop down list, specially because Windows WILL NOT display it in the task bar.  So every time i want to change or select an item from the form i have to go to the dialog, then view form list...  its not the end of the world.  I just think it could use a small improvement.There are icons in IDE's CoolBar to access units and forms (but not to center them). If you don't feel like clicking then use Shift+F12 and Ctrl+F12 to access these dialogs.