fpspreadsheet: Fix crash of worksheetGrid if methods using external workbooksource are accessed and only internal source is active.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4273 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-08-15 15:34:24 +00:00
parent adbc5c7c21
commit 2a0d2f2e0c
3 changed files with 11 additions and 10 deletions

View File

@ -79,6 +79,7 @@ object Form1: TForm1
FrozenCols = 0 FrozenCols = 0
FrozenRows = 0 FrozenRows = 0
ReadFormulas = False ReadFormulas = False
WorkbookSource = WorksheetGrid.internal
Align = alClient Align = alClient
AutoAdvance = aaDown AutoAdvance = aaDown
ColCount = 27 ColCount = 27

View File

@ -136,6 +136,7 @@ begin
Screen.Cursor := crHourglass; Screen.Cursor := crHourglass;
try try
WorksheetGrid.SaveToSpreadsheetFile(UTF8ToAnsi(SaveDialog.FileName)); WorksheetGrid.SaveToSpreadsheetFile(UTF8ToAnsi(SaveDialog.FileName));
//WorksheetGrid.WorkbookSource.SaveToSpreadsheetFile(UTF8ToAnsi(SaveDialog.FileName)); // works as well
finally finally
Screen.Cursor := crDefault; Screen.Cursor := crDefault;
// Show a message in case of error(s) // Show a message in case of error(s)

View File

@ -263,7 +263,7 @@ type
{ public properties } { public properties }
{@@ Link to the workbook } {@@ Link to the workbook }
property WorkbookSource: TsWorkbookSource read FWorkbookSource write SetWorkbookSource; property WorkbookSource: TsWorkbookSource read GetWorkbookSource write SetWorkbookSource;
{@@ Currently selected worksheet of the workbook } {@@ Currently selected worksheet of the workbook }
property Worksheet: TsWorksheet read GetWorksheet; property Worksheet: TsWorksheet read GetWorksheet;
{@@ Workbook displayed in the grid } {@@ Workbook displayed in the grid }
@ -849,6 +849,7 @@ end;
constructor TsCustomWorksheetGrid.Create(AOwner: TComponent); constructor TsCustomWorksheetGrid.Create(AOwner: TComponent);
begin begin
FInternalWorkbookSource := TsWorkbookSource.Create(self); //AOwner); FInternalWorkbookSource := TsWorkbookSource.Create(self); //AOwner);
FInternalWorkbookSource.Name := 'internal';
inherited Create(AOwner); inherited Create(AOwner);
AutoAdvance := aaDown; AutoAdvance := aaDown;
ExtendedSelect := true; ExtendedSelect := true;
@ -873,8 +874,6 @@ begin
SetWorkbookSource(nil); SetWorkbookSource(nil);
if FInternalWorkbookSource <> nil then if FInternalWorkbookSource <> nil then
FInternalWorkbookSource.RemoveListener(self); // will be destroyed automatically FInternalWorkbookSource.RemoveListener(self); // will be destroyed automatically
// FreeAndNil(FInternalWorkbookSource);
// end;
FreeAndNil(FCellFont); FreeAndNil(FCellFont);
inherited Destroy; inherited Destroy;
end; end;
@ -4348,6 +4347,13 @@ begin
end; end;
end; end;
function TsCustomWorksheetGrid.GetWorkbookSource: TsWorkbookSource;
begin
if FWorkbookSource <> nil then
Result := FWorkbookSource else
Result := FInternalWorkbookSource;
end;
function TsCustomWorksheetGrid.GetVertAlignment(ACol, ARow: Integer): TsVertAlignment; function TsCustomWorksheetGrid.GetVertAlignment(ACol, ARow: Integer): TsVertAlignment;
var var
cell: PCell; cell: PCell;
@ -4381,13 +4387,6 @@ begin
Result := GetWorkbookSource.Workbook; Result := GetWorkbookSource.Workbook;
end; end;
function TsCustomWorksheetGrid.GetWorkbookSource: TsWorkbookSource;
begin
if FWorkbookSource <> nil then
Result := FWorkbookSource else
Result := FInternalWorkbookSource;
end;
function TsCustomWorksheetGrid.GetWorksheet: TsWorksheet; function TsCustomWorksheetGrid.GetWorksheet: TsWorksheet;
begin begin
Result := GetWorkbookSource.Worksheet; Result := GetWorkbookSource.Worksheet;