Recent

Author Topic: (SOLVED) Merge cells example bug?!  (Read 1477 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 1752
(SOLVED) Merge cells example bug?!
« on: July 02, 2018, 02:51:32 pm »
Hi guys, I wanted to report a non-working example released with lazarus. This is the example to merge cells in TStringGrid. I have also attached the example, but if you compile and run mac (carbon) and double-click on a blank cell, it generates an exception in the DoEditorShow procedure. Does anyone know how to solve?
« Last Edit: July 02, 2018, 04:55:13 pm by xinyiman »
Ubuntu and Mac
Lazarus: 1.8.0
FPC: 3.0.4

wp

  • Hero Member
  • *****
  • Posts: 5129
Re: Merge cells example bug?!
« Reply #1 on: July 02, 2018, 03:22:48 pm »
I am the author of this example, but don't have access to Mac/carbon, and thus cannot reproduce on Win.

Double-click behavior of the standard grid was not modified in this example. Does the bug also occur with a standard string grid? There is a comment in TCustomGrid.DoEditorShow regarding carbon, but it has been there since at least version 1.6.4.

What exactly is the error message? Can you provide a stack trace?
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

xinyiman

  • Hero Member
  • *****
  • Posts: 1752
Re: Merge cells example bug?!
« Reply #2 on: July 02, 2018, 03:44:41 pm »
See if the images are clear enough.
Ubuntu and Mac
Lazarus: 1.8.0
FPC: 3.0.4

xinyiman

  • Hero Member
  • *****
  • Posts: 1752
Re: Merge cells example bug?!
« Reply #3 on: July 02, 2018, 03:44:58 pm »
Other
Ubuntu and Mac
Lazarus: 1.8.0
FPC: 3.0.4

wp

  • Hero Member
  • *****
  • Posts: 5129
Re: Merge cells example bug?!
« Reply #4 on: July 02, 2018, 03:52:02 pm »
Probably there is no editor. Modify TmcGrid.DoEditorShow like this and try again:

Code: Pascal  [Select]
  1. procedure TMCStringGrid.DoEditorShow;
  2. var
  3.   R: TRect;
  4. begin
  5.   inherited;
  6.   if goColSpanning in Options then begin
  7.     CalcCellExtent(Col, Row, R);
  8.     if Assigned(Editor) then   // <--- NEW
  9.       Editor.SetBounds(R.Left, R.Top, R.Right-R.Left-1, R.Bottom-R.Top-1);
  10.   end;
  11. end;
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

xinyiman

  • Hero Member
  • *****
  • Posts: 1752
Re: Merge cells example bug?!
« Reply #5 on: July 02, 2018, 03:59:55 pm »
He did not solve. But I do not understand a thing, if you look at the image 3 you will see that the right and the bottom of R are really great. Does not it seem strange?
Ubuntu and Mac
Lazarus: 1.8.0
FPC: 3.0.4

wp

  • Hero Member
  • *****
  • Posts: 5129
Re: Merge cells example bug?!
« Reply #6 on: July 02, 2018, 04:48:03 pm »
Ah, uninitialized variable! Try this
Code: Pascal  [Select]
  1. procedure TMCStringGrid.DoEditorShow;
  2. var
  3.   R: TRect;
  4. begin
  5.   inherited;
  6.   if (goColSpanning in Options) and Assigned(Editor) then begin
  7.     R := CellRect(Col, Row);
  8.     CalcCellExtent(Col, Row, R);
  9.     Editor.SetBounds(R.Left, R.Top, R.Right-R.Left-1, R.Bottom-R.Top-1);
  10.   end;
  11. end;
  12.  
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

xinyiman

  • Hero Member
  • *****
  • Posts: 1752
Re: Merge cells example bug?!
« Reply #7 on: July 02, 2018, 04:55:03 pm »
Perfect. Thank you
Ubuntu and Mac
Lazarus: 1.8.0
FPC: 3.0.4

wp

  • Hero Member
  • *****
  • Posts: 5129
Re: (SOLVED) Merge cells example bug?!
« Reply #8 on: July 02, 2018, 05:51:18 pm »
Applied to trunk. Thanks for reporting.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10