Recent

Author Topic: [SOLVED] TMemo or TSomething (NOT TStringGrid) for COLUMNS alternating text  (Read 3490 times)

JCobb

  • New Member
  • *
  • Posts: 15
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



« Last Edit: April 05, 2018, 03:23:51 am by JCobb »

wp

  • Hero Member
  • *****
  • Posts: 13324
The Grid is just a little too slow
How can you tell? What did you test?

and 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

  • New Member
  • *
  • Posts: 15
How 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.

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.

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.

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

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
« Last Edit: April 04, 2018, 08:04:43 pm by JCobb »

flowCRANE

  • Hero Member
  • *****
  • Posts: 937
Honestly 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.

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.  %)

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).
« Last Edit: April 04, 2018, 08:27:33 pm by furious programming »
Lazarus 4.2 with FPC 3.2.2, Windows 11 — all 64-bit

Working solo on a top-down retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL3.

JCobb

  • New Member
  • *
  • Posts: 15
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

  • Hero Member
  • *****
  • Posts: 4144
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

  • New Member
  • *
  • Posts: 15
For the time being I've examined enough example code to come up with the following solution:

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.strgdTextDisplayDrawCell(Sender: TObject; aCol,
  2.   aRow: Integer; aRect: TRect; aState: TGridDrawState);
  3. var
  4.   colwidth,
  5.   rowheight      : integer;
  6.  
  7. begin
  8.  
  9.   with strgdTextDisplay do
  10.    begin
  11.         colwidth := DefaultColWidth;
  12.         rowheight := DefaultRowHeight;
  13.         Canvas.Clear;
  14.         if (ACol = Col) and (ARow = Row) then
  15.            Canvas.Brush.Color := CursorColor;
  16.            Canvas.TextOut((ACol * colwidth) + 2, (ARow * rowheight) + 1,Cells[aCol,aRow]);
  17.    end;
  18.  
  19. 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

  • Hero Member
  • *****
  • Posts: 1578
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Maybe you could checked this:
http://tkweb.eu/en/delphicomp/khexeditor.html
I have never used it, though.
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

JCobb

  • New Member
  • *
  • Posts: 15
Maybe 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.

 

TinyPortal © 2005-2018