Recent

Author Topic: NiceGrid component for Laxarus  (Read 1084 times)

Alexandr R

  • New Member
  • *
  • Posts: 33
NiceGrid component for Laxarus
« on: April 10, 2026, 06:51:02 pm »
[Google Translate]
Hello. I have a few questions about the NiceGrid component. After executing the NgDrawCell method:
Code: Pascal  [Select][+][-]
  1. procedure Tfr_Main.NgDrawCell(Sender: TObject; ACanvas:  Canvas; X, Y: Integer; Rc: TRect; var Handled: Boolean);                                                                                    
  2. begin
  3.   if (X = NgColNN) or (X = NgColRem) or (X = NgColFlg) then
  4.     exit;
  5.  if Ng.Cells[NgColFlg, Y] = NgFlagNotUse then
  6.    begin
  7.      ACanvas.Font.Color:= clGradientInactiveCaption; {*}
  8.      ACanvas.Font.Style:= [fsStrikeOut];                    {*}
  9.      Ng.Invalidate;
  10.   end;
  11. end;

    Strange things are happening. The main program window stops responding to the "Close" command, and the "Mini-mize" command in the main window causes the program to close. When changing the right grid border, when the table border (almost) coincides with the main window border, the borders sometimes start flickering and this process loops. Commenting out the lines marked with {*} returns the behavior of the main program window to normal.
Am I doing something wrong?

     And two more questions. How can I keep the table cell editor running permanently, without pressing [F2]? What event should I use to validate the value entered in a cell?
The project data is in the ReCalcXY.zip archive (https://disk.yandex.ru/d/mBJrI4JcZtbYww). OS: Windows 11 LTSC 64-bit; Lazarus 4.6, fps 3.2.2 64-bit.
Thanks in advance.
Sincerely, Alexander

wp

  • Hero Member
  • *****
  • Posts: 13513
Re: NiceGrid component for Laxarus
« Reply #1 on: April 10, 2026, 08:23:35 pm »
Please don't post projects to some cloud services, upload them directly here to the forum (--> Attachments and other options). This way the attachment will still be available even after you deleted the project from that other cloud.

And it would be helpful if you'd remove unneeded dependencies (ATFlatControls) from the test project. Remove also the password-protected zip from the uploaded file itself, it is not needed and just confusing.

The program hangs becauses you call Invalidate from your DrawCell Handler. This trigger another drawing cycle which calls DrawCell again which triggers yet another drawing cycle ...

Removing this makes the program responsive again. I assume that when there is a '-' in column "Flg" all cells should be drawn in strike-out style, correct? This does not happen, I'll have to investigate. NiceGrid is not "my" component, but I ported it to Lazarus, and therefore I feel responsible. Basically your idea should be working, but I don't know yet whether this is handled correctly by TNiceGrid.

wp

  • Hero Member
  • *****
  • Posts: 13513
Re: NiceGrid component for Laxarus
« Reply #2 on: April 11, 2026, 12:03:57 am »
OK, found it: the Invalidate was important, but it was at the wrong place. Rather than in the OnDrawCell event, it should be called from the OnCellChange event which does not trigger recursion:

Code: Pascal  [Select][+][-]
  1. procedure Tfr_Main.NGCellChange(Sender: TObject; Col, Row: Integer;
  2.   var Str: string);
  3. begin
  4.   if Col = NgColFlg then Ng.Invalidate;
  5. end;

As for validating the cell input and keeping the cell editor active without pressing F2: I don't know for sure (as I said, I am not the author of the component), but it looks to me as if the grid is not prepared for these features. This does not mean that they cannot be added, but it requires some work.

Alexandr R

  • New Member
  • *
  • Posts: 33
Re: NiceGrid component for Laxarus
« Reply #3 on: April 12, 2026, 11:02:54 am »
 :)Google Translate
Hello. I'm having trouble explaining what happened, but the program worked as expected.
Thanks, WP, for your attention.  The Tfr_Main.NGCellChange method doesn't fire when the
data is changed by the program in a cell belonging to the NgColFlg column, but it does fire
when changed manually.  The previous post  contains the  program's executable file in the
archive; it's  not needed.  The password is: Agent007  (the first letter may be lowercase).
The archive has been updated.

 

TinyPortal © 2005-2018