From 8de5a73097e895e63779a910bc3f8a88865a11bc Mon Sep 17 00:00:00 2001 From: juha Date: Sun, 29 Oct 2017 21:20:57 +0000 Subject: [PATCH] LCL: Prevent a crash when getting editor for an empty Grid. Issue #32623, patch from C Western. git-svn-id: trunk@56235 - --- lcl/grids.pas | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lcl/grids.pas b/lcl/grids.pas index 22b4bc24ae..07efab14d7 100644 --- a/lcl/grids.pas +++ b/lcl/grids.pas @@ -1258,6 +1258,7 @@ type procedure AutoAdjustColumns; virtual; procedure BeginUpdate; function CellRect(ACol, ARow: Integer): TRect; + function CellRectValid(ACol, ARow: Integer; out ARect: TRect): Boolean; function CellToGridZone(aCol,aRow: Integer): TGridZone; procedure CheckPosition; function ClearCols: Boolean; @@ -3421,12 +3422,18 @@ begin end; end; -{ Returns a reactagle corresponding to a fisical cell[aCol,aRow] } +{ Returns a reactagle corresponding to a physical cell[aCol,aRow] } function TCustomGrid.CellRect(ACol, ARow: Integer): TRect; begin - //Result:=ColRowToClientCellRect(aCol,aRow); - ColRowToOffset(True, True, ACol, Result.Left, Result.Right); - ColRowToOffSet(False,True, ARow, Result.Top, Result.Bottom); + Assert( (AColnil) then begin @@ -8219,9 +8227,11 @@ begin FEditor.Dispatch(Msg); // send editor bounds - CellR:=CellRect(FCol,FRow); + PosValid := CellRectValid(FCol, FRow, CellR); + if not PosValid then // Can't position editor; ensure sane values + CellR := Rect(0,0,FEditor.Width, FEditor.Height); - if (CellR.TopFGCache.ClientHeight) or + if not PosValid or (CellR.TopFGCache.ClientHeight) or (UseRightToLeftAlignment and ((CellR.Right-1>FlipX(FGCache.FixedWidth)) or (CellR.Right<0))) or (not UseRightToLeftAlignment and ((CellR.LeftFGCache.ClientWidth))) then