mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 21:16:05 +02:00
LCL, fix stringgrid's autosizecolumn crash, issue #12812
git-svn-id: trunk@18486 -
This commit is contained in:
parent
f858cdf155
commit
8cee5efb85
@ -8387,16 +8387,40 @@ procedure TCustomStringGrid.AutoAdjustColumn(aCol: Integer);
|
|||||||
var
|
var
|
||||||
i,W: Integer;
|
i,W: Integer;
|
||||||
Ts: TSize;
|
Ts: TSize;
|
||||||
|
TmpCanvas: TCanvas;
|
||||||
|
DC: HDC;
|
||||||
begin
|
begin
|
||||||
if (aCol<0)or(aCol>ColCount-1) then Exit;
|
if (aCol<0) or (aCol>ColCount-1) then
|
||||||
W:=0;
|
Exit;
|
||||||
For i:=0 to RowCount-1 do begin
|
|
||||||
Ts:=Canvas.TextExtent(Cells[aCol, i]);
|
if not Canvas.HandleAllocated then begin
|
||||||
if Ts.Cx>W then W:=Ts.Cx;
|
DC := GetDC(0);
|
||||||
|
TmpCanvas := TCanvas.Create;
|
||||||
|
TmpCanvas.Handle := DC;
|
||||||
|
TmpCanvas.Font.Assign(Font);
|
||||||
|
end else
|
||||||
|
TmpCanvas := Canvas;
|
||||||
|
|
||||||
|
try
|
||||||
|
W:=0;
|
||||||
|
for i := 0 to RowCount-1 do begin
|
||||||
|
Ts := TmpCanvas.TextExtent(Cells[aCol, i]);
|
||||||
|
if Ts.Cx>W then
|
||||||
|
W := Ts.Cx;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
if not Canvas.HandleAllocated then begin
|
||||||
|
TmpCanvas.Free;
|
||||||
|
ReleaseDC(0, DC);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
if W=0 then W:=DefaultColWidth
|
|
||||||
else W:=W + 8;
|
if W=0 then
|
||||||
ColWidths[aCol]:=W;
|
W := DefaultColWidth
|
||||||
|
else
|
||||||
|
W := W + 8;
|
||||||
|
|
||||||
|
ColWidths[aCol] := W;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomStringGrid.CalcCellExtent(acol, aRow: Integer; var aRect: TRect);
|
procedure TCustomStringGrid.CalcCellExtent(acol, aRow: Integer; var aRect: TRect);
|
||||||
|
Loading…
Reference in New Issue
Block a user