You've already forked lazarus-ccr
fpspreadsheet: Fix crash of visual controls when workbook.RemoveAllWorksheets is called. Visual controls can handle the case of active worksheet = nil.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5937 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -688,7 +688,7 @@ type
|
||||
{@@ Event procedure containing a specific worksheet }
|
||||
TsWorksheetEvent = procedure (Sender: TObject; ASheet: TsWorksheet) of object;
|
||||
|
||||
{@@ Event procedure called when a worksheet is removed }
|
||||
{@@ Event procedure called when a worksheet is removed. ASheetIndex = -1 --> all sheets }
|
||||
TsRemoveWorksheetEvent = procedure (Sender: TObject; ASheetIndex: Integer) of object;
|
||||
|
||||
|
||||
@ -8051,7 +8051,9 @@ end;
|
||||
-------------------------------------------------------------------------------}
|
||||
destructor TsWorkbook.Destroy;
|
||||
begin
|
||||
DisableNotifications;
|
||||
RemoveAllWorksheets;
|
||||
EnableNotifications;
|
||||
FWorksheets.Free;
|
||||
|
||||
FCellFormatList.Free;
|
||||
@ -8791,7 +8793,11 @@ end;
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsWorkbook.RemoveAllWorksheets;
|
||||
begin
|
||||
FActiveWorksheet := nil;
|
||||
FWorksheets.ForEachCall(RemoveWorksheetsCallback, nil);
|
||||
FWorksheets.Clear;
|
||||
if (FLockCount = 0) and Assigned(FOnRemoveWorksheet) then
|
||||
FOnRemoveWorksheet(self, -1);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
|
@ -1610,7 +1610,11 @@ begin
|
||||
else
|
||||
sheet := Workbook.GetWorksheetbyIndex(ASheetIndex);
|
||||
end else
|
||||
sheet := FWorksheet;
|
||||
if ASheetIndex > -1 then
|
||||
sheet := FWorksheet
|
||||
else
|
||||
sheet := nil; // all sheets were removed
|
||||
|
||||
// FWorksheet := sheet; // is needed by listeners!
|
||||
NotifyListeners([lniWorksheetRemove]);
|
||||
SelectWorksheet(sheet);
|
||||
@ -1882,6 +1886,9 @@ end;
|
||||
|
||||
procedure TsCellEdit.DoEnter;
|
||||
begin
|
||||
if Worksheet = nil then
|
||||
exit;
|
||||
|
||||
if not CanEditCell(Worksheet.ActiveCellRow, Worksheet.ActiveCellCol) then
|
||||
begin
|
||||
MessageDlg('This cell is protected from editing. Unlock worksheet protection '+
|
||||
|
@ -2242,6 +2242,8 @@ var
|
||||
TL: TPoint;
|
||||
begin
|
||||
inherited;
|
||||
if Worksheet = nil then
|
||||
exit;
|
||||
|
||||
FTopLeft := CalcTopLeft(false);
|
||||
|
||||
@ -4351,6 +4353,9 @@ var
|
||||
clipArea: TRect;
|
||||
|
||||
begin
|
||||
if Worksheet = nil then
|
||||
exit;
|
||||
|
||||
sr := GetWorksheetRow(ARow);
|
||||
scLastused := Worksheet.GetLastColIndex;
|
||||
gc := AFirstCol;
|
||||
@ -4966,6 +4971,9 @@ var
|
||||
cell: PCell;
|
||||
r, c: Cardinal;
|
||||
begin
|
||||
if Worksheet = nil then
|
||||
exit;
|
||||
|
||||
if FAllowDragAndDrop and
|
||||
(not Assigned(DragManager) or not DragManager.IsDragging) and
|
||||
(ssLeft in Shift) and
|
||||
@ -5016,6 +5024,9 @@ procedure TsCustomWorksheetGrid.MouseMove(Shift: TShiftState; X, Y: Integer);
|
||||
var
|
||||
prevMouseCell: TPoint;
|
||||
begin
|
||||
if Worksheet = nil then
|
||||
exit;
|
||||
|
||||
prevMouseCell := GCache.MouseCell;
|
||||
|
||||
inherited;
|
||||
@ -5264,7 +5275,7 @@ var
|
||||
cp: TsCellprotections;
|
||||
begin
|
||||
Result := inherited;
|
||||
if Result and Worksheet.IsProtected then
|
||||
if Result and Assigned(Worksheet) and Worksheet.IsProtected then
|
||||
begin
|
||||
cell := Worksheet.FindCell(GetWorksheetRow(ARow), GetWorksheetCol(ACol));
|
||||
cp := Worksheet.ReadCellProtection(cell);
|
||||
|
Reference in New Issue
Block a user