Commit 8de5a730 authored by Juha Manninen's avatar Juha Manninen
Browse files

LCL: Prevent a crash when getting editor for an empty Grid. Issue #32623, patch from C Western.

git-svn-id: trunk@56235 -
parent 7a60c60d
......@@ -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
{ 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;
ColRowToOffset(True, True, ACol, Result.Left, Result.Right);
ColRowToOffSet(False,True, ARow, Result.Top, Result.Bottom);
Assert( (ACol<ColCount) and (ARow<RowCount),
Format('TCustomGrid.CellRect: ACol (%d) or ARow (%d) out of range.',[ACol,ARow]) );
CellRectValid(ACol, ARow, Result);
function TCustomGrid.CellRectValid(ACol, ARow: Integer; out ARect: TRect): Boolean;
Result := ColRowToOffset(True, True, ACol, ARect.Left, ARect.Right)
and ColRowToOffSet(False,True, ARow, ARect.Top, ARect.Bottom);
// The visible grid Depends on TopLeft and ClientWidht,ClientHeight,
......@@ -8207,6 +8214,7 @@ procedure TCustomGrid.EditorPos;
msg: TGridMessage;
CellR: TRect;
PosValid: Boolean;
{$ifdef dbgGrid} DebugLn('Grid.EditorPos INIT');{$endif}
if HandleAllocated and (FEditor<>nil) then begin
......@@ -8219,9 +8227,11 @@ begin
// send editor bounds
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.Top<FGCache.FixedHeight) or (CellR.Top>FGCache.ClientHeight) or
if not PosValid or (CellR.Top<FGCache.FixedHeight) or (CellR.Top>FGCache.ClientHeight) or
(UseRightToLeftAlignment and ((CellR.Right-1>FlipX(FGCache.FixedWidth)) or (CellR.Right<0))) or
(not UseRightToLeftAlignment and ((CellR.Left<FGCache.FixedWidth) or (CellR.Left>FGCache.ClientWidth)))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment