[SOLVED] TMemo or TSomething (NOT TStringGrid) for COLUMNS alternating text lazarus / 31-LCL ---------------------------------------------------------------------- JCobb · 2018-04-04 17:17 Hi All, I spent most the day yesterday trying to find a way to utilize something other than a TStringGrid for my project.  The Grid is just a little too slow and each grid cell has a padding around it that prevents making really narrow cells for storing single characters.  I want to avoid the extra space in the cells.  In essence I'm making a binary file reader that has two grids: one for showing the raw character data and another for showing the Hex equivalent of that data. I thought about using an HTML Panel but the memory usage is too high. So I was thinking that a Memo or maybe a SynEdit would work great (although I think a Memo is much faster).  Unfortunately I haven't been able to figure out how to make the colors alternate on a column by column basis.  I also need some kind of cursor with a different background and foreground color to show which position I'm at.  Something like the sample image I've attached would be perfect. I'd appreciate any pointers on this subject. Thanks in advance, Jeff ---------------------------------------------------------------------- wp · 2018-04-04 17:44 Quote from: JCobb on April 04, 2018, 07:17:02 pmThe Grid is just a little too slowHow can you tell? What did you test? Quote from: JCobb on April 04, 2018, 07:17:02 pmand each grid cell has a padding around it that prevents making really narrow cells for storing single characters.The cellPadding is two pixels to the left and right each. But why don't you do custom-painting (event OnDrawCell), this way you can avoid the cellPadding. The cell width itself is only limited by 0. But believe me: characters squeezed into such tight cells look terrible. BTW, a hex editor ready to be clicked onto the form is contained the the KControls package (see OPM). I used it in several projects ---------------------------------------------------------------------- JCobb · 2018-04-04 17:57 Quote from: wp on April 04, 2018, 07:44:23 pmHow can you tell? What did you test? Honestly the speed of the TStringGrid is "OK".  But the TMemo displays the data much faster.  I'd prefer it if possible. Quote from: wp on April 04, 2018, 07:44:23 pmThe cellPadding is two pixels to the left and right each. But why don't you do custom- painting (event OnDrawCell), this way you can avoid the cellPadding. The cell width itself is only limited by 0. But believe me: characters squeezed into such tight cells look terrible. I have another StringGrid that displays the raw text data and in this particular case THAT looks terrible.  The grid has padding in each cell that I'd like to remove or shrink so the characters are much closer together.  I use a monospace font so the font size is predictable. I'd be willing to keep the grid if I could reduce the padding.  Eventually though I'd like to use a component that offers much faster rendering. Quote from: wp on April 04, 2018, 07:44:23 pmBTW, a hex editor ready to be clicked onto the form is contained the the KControls package (see OPM). I used it in several projects I've experience with Pascal in general.  But I'm pretty new to Lazarus and  the advanced manipulation of objects you're talking about I've yet to entirely grasp.   i.e.  I don't know  what "OPM" is or where the KControls package is.  I've attached a sample of what I have already. Jeff ---------------------------------------------------------------------- flowCRANE · 2018-04-04 18:19 Quote from: JCobb on April 04, 2018, 07:57:33 pmHonestly the speed of the TStringGrid is "OK".  But the TMemo displays the data much faster.  I'd prefer it if possible. Yes, but TMemo has one TStringList inside, instead of TStringGrid, which has many of this lists, so the performance is worse. Quote from: JCobb on April 04, 2018, 07:57:33 pmI've experience with Pascal in general.  But I'm pretty new to Lazarus and  the advanced manipulation of objects you're talking about I've yet to entirely grasp.   i.e.  I don't know  what "OPM" is or where the KControls package is.  Don't worry. Go to this site, download the latest file, unzip, open package file in Lazarus, recompile it and install. After all, you will see additional controls on the components palette (with TKHexEditor component). ---------------------------------------------------------------------- JCobb · 2018-04-04 19:50 I've found plenty of information on how to modify the Grid's brush color but next to nothing on changing it's size or removing the padding. Any references on this? Jeff ---------------------------------------------------------------------- howardpc · 2018-04-04 19:52 Since you want a read-only display control, it's simple to roll your own. See the attached project for an example you can adapt. ---------------------------------------------------------------------- JCobb · 2018-04-04 23:45 For the time being I've examined enough example code to come up with the following solution: 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 TfrmMain.strgdTextDisplayDrawCell(Sender: TObject; aCol,  aRow: Integer; aRect: TRect; aState: TGridDrawState);var  colwidth,  rowheight      : integer; begin   with strgdTextDisplay do   begin      colwidth := DefaultColWidth;        rowheight := DefaultRowHeight;        Canvas.Clear;        if (ACol = Col) and (ARow = Row) then         Canvas.Brush.Color := CursorColor;           Canvas.TextOut((ACol * colwidth) + 2, (ARow * rowheight) + 1,Cells[aCol,aRow]);   end; end;   It works like I want it to and I've attached an image to show the results I have.  I wouldn't speak to it's performance.  I think harwardpc's example might improve on that but I need mouse and keyboard events in the code. Thanks for the help, Jeff ---------------------------------------------------------------------- CM630 · 2018-04-05 11:11 Maybe you could checked this: http://tkweb.eu/en/delphicomp/khexeditor.html I have never used it, though. ---------------------------------------------------------------------- JCobb · 2018-04-05 14:41 Quote from: CM630 on April 05, 2018, 01:11:03 pmMaybe you could checked this: http://tkweb.eu/en/delphicomp/khexeditor.html I have never used it, though. I did check that out.  It looked promising but I didn't see any support for the Mac.