fpspreadsheet: Fix reference to workbook in TsWorkbookChartLink

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9429 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-09-08 20:39:45 +00:00
parent 18f3689db7
commit 095be0e60d
2 changed files with 23 additions and 11 deletions

View File

@ -131,11 +131,11 @@ type
FChart: TChart; FChart: TChart;
FChartStyles: TChartStyles; FChartStyles: TChartStyles;
FWorkbookSource: TsWorkbookSource; FWorkbookSource: TsWorkbookSource;
FWorkbook: TsWorkbook;
FWorkbookChartIndex: Integer; FWorkbookChartIndex: Integer;
FBrushBitmaps: TFPObjectList; FBrushBitmaps: TFPObjectList;
FSavedAfterDraw: TChartDrawEvent; FSavedAfterDraw: TChartDrawEvent;
FLogLabelSource: TListChartSource; FLogLabelSource: TListChartSource;
function GetWorkbook: TsWorkbook;
procedure SetChart(AValue: TChart); procedure SetChart(AValue: TChart);
procedure SetWorkbookChartIndex(AValue: Integer); procedure SetWorkbookChartIndex(AValue: Integer);
procedure SetWorkbookSource(AValue: TsWorkbookSource); procedure SetWorkbookSource(AValue: TsWorkbookSource);
@ -195,6 +195,7 @@ type
{ Interfacing with WorkbookSource} { Interfacing with WorkbookSource}
procedure ListenerNotification(AChangedItems: TsNotificationItems; AData: Pointer = nil); procedure ListenerNotification(AChangedItems: TsNotificationItems; AData: Pointer = nil);
procedure RemoveWorkbookSource; procedure RemoveWorkbookSource;
property Workbook: TsWorkbook read GetWorkbook;
published published
property Chart: TChart read FChart write SetChart; property Chart: TChart read FChart write SetChart;
@ -1377,9 +1378,9 @@ var
axis: TsChartAxis; axis: TsChartAxis;
begin begin
ser := ActiveChartSeries(ASeries); ser := ActiveChartSeries(ASeries);
if ser = nil then if (ser = nil) or (Workbook = nil) then
begin begin
FWorkbook.AddErrorMsg('Series could not be loaded.'); Workbook.AddErrorMsg('Series could not be loaded.');
exit; exit;
end; end;
@ -1501,6 +1502,8 @@ begin
FChart.Frame.Width := 1; FChart.Frame.Width := 1;
FChart.Frame.Style := psSolid; FChart.Frame.Style := psSolid;
FChart.Frame.Visible := true; FChart.Frame.Visible := true;
// FChart.OnAfterDraw := FSavedAfterDraw;
end; end;
{ Approximates the empty hatch patterns by the built-in TBrush styles. } { Approximates the empty hatch patterns by the built-in TBrush styles. }
@ -1885,8 +1888,16 @@ end;
function TsWorkbookChartLink.GetWorkbookChart: TsChart; function TsWorkbookChartLink.GetWorkbookChart: TsChart;
begin begin
if (FWorkbook <> nil) and (FWorkbookChartIndex > -1) then if (Workbook <> nil) and (FWorkbookChartIndex > -1) then
Result := FWorkbook.GetChartByIndex(FWorkbookChartIndex) Result := Workbook.GetChartByIndex(FWorkbookChartIndex)
else
Result := nil;
end;
function TsWorkbookChartlink.GetWorkbook: TsWorkbook;
begin
if FWorkbookSource <> nil then
Result := FWorkbookSource.Workbook
else else
Result := nil; Result := nil;
end; end;
@ -1947,7 +1958,10 @@ begin
// Workbook has been successfully loaded, all sheets are ready // Workbook has been successfully loaded, all sheets are ready
if (lniWorkbook in AChangedItems) then if (lniWorkbook in AChangedItems) then
begin
ClearChart; ClearChart;
UpdateChart;
end;
end; end;
procedure TsWorkbookChartLink.Notification(AComponent: TComponent; Operation: TOperation); procedure TsWorkbookChartLink.Notification(AComponent: TComponent; Operation: TOperation);
@ -1998,11 +2012,7 @@ begin
FWorkbookSource.RemoveListener(self); FWorkbookSource.RemoveListener(self);
FWorkbookSource := AValue; FWorkbookSource := AValue;
if FWorkbookSource <> nil then if FWorkbookSource <> nil then
begin
FWorkbookSource.AddListener(self); FWorkbookSource.AddListener(self);
FWorkbook := FWorkbookSource.Workbook;
end else
FWorkbook := nil;
ListenerNotification([lniWorkbook, lniWorksheet]); ListenerNotification([lniWorkbook, lniWorksheet]);
UpdateChart; UpdateChart;
end; end;

View File

@ -1184,7 +1184,8 @@ begin
AWorkbook.DisableNotifications; AWorkbook.DisableNotifications;
if AWorkbook <> FWorkbook then if AWorkbook <> FWorkbook then
InternalCreateNewWorkbook(AWorkbook) else InternalCreateNewWorkbook(AWorkbook)
else
SetOptions(FOptions); SetOptions(FOptions);
WorkbookOpenedHandler(self); WorkbookOpenedHandler(self);
@ -1734,7 +1735,8 @@ begin
Unused(Sender); Unused(Sender);
NotifyListeners([lniWorkbook]); NotifyListeners([lniWorkbook]);
if FWorkbook.ActiveWorksheet = nil then if FWorkbook.ActiveWorksheet = nil then
SelectWorksheet(FWorkbook.GetFirstWorksheet) else SelectWorksheet(FWorkbook.GetFirstWorksheet)
else
SelectWorksheet(FWorkbook.ActiveWorksheet); SelectWorksheet(FWorkbook.ActiveWorksheet);
end; end;