From 96ffaaa4d297df1ae837b83e56a2cdba9cebcee9 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 9 Aug 2017 22:52:49 +0000 Subject: [PATCH] fpspreadsheet: Fix crash of db_import_export demo in virtual mode. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5993 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/db_import_export/main.lfm | 3 +-- .../examples/db_import_export/main.pas | 5 +++-- .../source/common/fpsopendocument.pas | 22 +++++++++---------- .../source/common/fpspreadsheet.pas | 2 +- .../fpspreadsheet/source/common/fpsutils.pas | 10 +++++---- .../fpspreadsheet/source/common/wikitable.pas | 4 ++-- .../fpspreadsheet/source/common/xlsbiff2.pas | 12 +++++----- .../fpspreadsheet/source/common/xlsbiff5.pas | 4 ++-- .../fpspreadsheet/source/common/xlsbiff8.pas | 6 ++--- .../fpspreadsheet/source/common/xlscommon.pas | 17 +++++++------- .../fpspreadsheet/source/common/xlsxooxml.pas | 4 ++-- .../source/export/fpsexportreg.pas | 2 +- .../source/visual/fpspreadsheetctrls.pas | 2 +- .../source/visual/fpspreadsheetgrid.pas | 5 ++--- 14 files changed, 50 insertions(+), 48 deletions(-) diff --git a/components/fpspreadsheet/examples/db_import_export/main.lfm b/components/fpspreadsheet/examples/db_import_export/main.lfm index e7fa6d9a6..d1bd429b9 100644 --- a/components/fpspreadsheet/examples/db_import_export/main.lfm +++ b/components/fpspreadsheet/examples/db_import_export/main.lfm @@ -8,7 +8,7 @@ object Form1: TForm1 ClientWidth = 521 OnCreate = FormCreate OnDestroy = FormDestroy - LCLVersion = '1.7' + LCLVersion = '1.9.0.0' object PageControl: TPageControl Left = 4 Height = 302 @@ -274,7 +274,6 @@ object Form1: TForm1 Anchors = [akTop, akLeft, akBottom] ItemHeight = 0 OnClick = FileListClick - Options = [lboDrawFocusRect] TabOrder = 1 end object Label3: TLabel diff --git a/components/fpspreadsheet/examples/db_import_export/main.pas b/components/fpspreadsheet/examples/db_import_export/main.pas index 918083cd6..b67890a6f 100644 --- a/components/fpspreadsheet/examples/db_import_export/main.pas +++ b/components/fpspreadsheet/examples/db_import_export/main.pas @@ -514,6 +514,7 @@ begin FWorkbook := TsWorkbook.Create; try + FWorkbook.FormatSettings.ShortDateFormat := 'dd.mm.yyyy "r."'; worksheet := FWorkbook.AddWorksheet(tableName); // Make header line frozen - but not in Excel2 where frozen panes do not yet work properly @@ -614,7 +615,7 @@ begin cctNumber : if IsCurrencyFormat(nfp) then fieldType := ftCurrency else fieldType := ftFloat; cctDateTime : fieldType := ftDateTime; - cctUTF8String : fieldType := ftString; + else fieldType := ftString; end; FImportDataset.FieldDefs.Add(FImportedFieldNames[i], fieldType); end; @@ -629,7 +630,7 @@ begin case FImportedRowCells[i].ContentType of cctNumber : FImportDataset.Fields[i].AsFloat := FImportedRowCells[i].NumberValue; cctDateTime : FImportDataset.Fields[i].AsDateTime := FImportedRowCells[i].DateTimeValue; - cctUTF8String: FImportDataset.Fields[i].AsString := FImportedRowCells[i].UTF8StringValue; + else FImportDataset.Fields[i].AsString := FImportedRowCells[i].UTF8StringValue; end; FImportDataset.Post; // Finally we dispose the buffered cells, we don't need them any more diff --git a/components/fpspreadsheet/source/common/fpsopendocument.pas b/components/fpspreadsheet/source/common/fpsopendocument.pas index 3a4a638be..923dd693c 100644 --- a/components/fpspreadsheet/source/common/fpsopendocument.pas +++ b/components/fpspreadsheet/source/common/fpsopendocument.pas @@ -1778,7 +1778,7 @@ begin if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -1798,7 +1798,7 @@ var begin if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -1997,7 +1997,7 @@ var begin if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -2023,7 +2023,7 @@ var begin if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -2311,7 +2311,7 @@ begin // Create cell and apply format if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.GetCell(ARow, ACol); // Don't use AddCell here @@ -2643,7 +2643,7 @@ begin // Initalize cell if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -2760,7 +2760,7 @@ var begin if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -3559,7 +3559,7 @@ var else begin // No cell in row --> appy format to dummy cell to get its format index - InitCell(row, 0, cellRecord); + InitCell(FWorksheet, row, 0, cellRecord); ApplyStyleToCell(@cellRecord, styleIndex); lRow^.FormatIndex := cellRecord.FormatIndex; end; @@ -3618,7 +3618,7 @@ var if cell <> nil then colFmt[col] := cell^.FormatIndex else begin - InitCell(row, col, cellRecord); + InitCell(FWorksheet, row, col, cellRecord); ApplyStyleToCell(@cellRecord, styleIndex); colFmt[col] := cellRecord.FormatIndex; end; @@ -7327,7 +7327,7 @@ begin colsRepeated := 1; lCell.Row := r; // to silence a compiler hint... - InitCell(r, c, lCell); + InitCell(ASheet, r, c, lCell); value := varNull; styleCell := nil; @@ -7339,7 +7339,7 @@ begin cc := c + 1; while (cc <= lastCol) do begin - InitCell(r, cc, lCell); + InitCell(ASheet, r, cc, lCell); value := varNull; styleCell := nil; ASheet.OnWriteCellData(ASheet, r, cc, value, styleCell); diff --git a/components/fpspreadsheet/source/common/fpspreadsheet.pas b/components/fpspreadsheet/source/common/fpspreadsheet.pas index 9e9625a4c..3a81e1bdf 100644 --- a/components/fpspreadsheet/source/common/fpspreadsheet.pas +++ b/components/fpspreadsheet/source/common/fpspreadsheet.pas @@ -2274,7 +2274,7 @@ begin WriteComment(r, c, ''); // Erase all cell content - InitCell(r, c, ACell^); + InitCell(nil, r, c, ACell^); end; end; diff --git a/components/fpspreadsheet/source/common/fpsutils.pas b/components/fpspreadsheet/source/common/fpsutils.pas index 70b00e4cc..e9a770335 100644 --- a/components/fpspreadsheet/source/common/fpsutils.pas +++ b/components/fpspreadsheet/source/common/fpsutils.pas @@ -174,7 +174,7 @@ procedure SplitHyperlink(AValue: String; out ATarget, ABookmark: String); procedure FixHyperlinkPathDelims(var ATarget: String); procedure InitCell(out ACell: TCell); overload; -procedure InitCell(ARow, ACol: Cardinal; out ACell: TCell); overload; +procedure InitCell(AWorksheet: Pointer; ARow, ACol: Cardinal; out ACell: TCell); overload; procedure InitCryptoInfo(out AValue: TsCryptoInfo); procedure InitFormatRecord(out AValue: TsCellFormat); procedure InitImageRecord(out AValue: TsImage; ARow, ACol: Cardinal; @@ -2105,13 +2105,15 @@ end; Initalizes a new cell and presets the row and column fields of the cell record to the parameters passed to the procedure. - @param ARow Row index of the new cell - @param ACol Column index of the new cell + @param AWorksheet Pointer to the worksheet containing the cell + @param ARow Row index of the new cell + @param ACol Column index of the new cell @return New cell record with row and column fields preset to passed values. -------------------------------------------------------------------------------} -procedure InitCell(ARow, ACol: Cardinal; out ACell: TCell); +procedure InitCell(AWorksheet: Pointer; ARow, ACol: Cardinal; out ACell: TCell); begin InitCell(ACell); + ACell.Worksheet := AWorksheet; ACell.Row := ARow; ACell.Col := ACol; end; diff --git a/components/fpspreadsheet/source/common/wikitable.pas b/components/fpspreadsheet/source/common/wikitable.pas index f16465127..6c7344871 100644 --- a/components/fpspreadsheet/source/common/wikitable.pas +++ b/components/fpspreadsheet/source/common/wikitable.pas @@ -492,13 +492,13 @@ begin // Column width (to be considered in first row) if i = 0 then lColWidthStr := Format(' width="%.0fpt"', [ - FWorkbook.ConvertUnits(FWorksheet.GetColWidth(i), FWorkbook.Units, suPoints) + FWorkbook.ConvertUnits(FWorksheet.GetColWidth(i, suChars), FWorkbook.Units, suPoints) ]); // Row height (to be considered in first column) if j = 0 then lRowHeightStr := Format(' height="%.0fpt"', [ - FWorkbook.ConvertUnits(FWorksheet.GetRowHeight(j), FWorkbook.Units, suPoints) + FWorkbook.ConvertUnits(FWorksheet.GetRowHeight(j, suLines), FWorkbook.Units, suPoints) ]); // Font diff --git a/components/fpspreadsheet/source/common/xlsbiff2.pas b/components/fpspreadsheet/source/common/xlsbiff2.pas index 6890252b9..46b3b1302 100644 --- a/components/fpspreadsheet/source/common/xlsbiff2.pas +++ b/components/fpspreadsheet/source/common/xlsbiff2.pas @@ -328,7 +328,7 @@ var begin ReadRowColXF(AStream, ARow, ACol, XF); if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -358,7 +358,7 @@ begin { Create cell } if FIsVirtualMode then begin - InitCell(r, c, FVirtualCell); + InitCell(FWorksheet, r, c, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(r, c); @@ -687,7 +687,7 @@ begin { Create cell } if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -782,7 +782,7 @@ begin { Create cell } if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -817,7 +817,7 @@ begin {Create cell} if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -856,7 +856,7 @@ begin { Create cell } if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); diff --git a/components/fpspreadsheet/source/common/xlsbiff5.pas b/components/fpspreadsheet/source/common/xlsbiff5.pas index c24b26793..c5ca1e3b3 100644 --- a/components/fpspreadsheet/source/common/xlsbiff5.pas +++ b/components/fpspreadsheet/source/common/xlsbiff5.pas @@ -657,7 +657,7 @@ begin { Create cell } if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -1095,7 +1095,7 @@ begin { Create cell } if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); diff --git a/components/fpspreadsheet/source/common/xlsbiff8.pas b/components/fpspreadsheet/source/common/xlsbiff8.pas index edd429b4a..6df0d6ca2 100644 --- a/components/fpspreadsheet/source/common/xlsbiff8.pas +++ b/components/fpspreadsheet/source/common/xlsbiff8.pas @@ -1051,7 +1051,7 @@ begin { Save the data } if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); // "virtual" cell + InitCell(FWorksheet, ARow, ACol, FVirtualCell); // "virtual" cell cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); // "real" cell @@ -1293,7 +1293,7 @@ begin { Create cell } if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); // "virtual" cell + InitCell(FWorksheet, ARow, ACol, FVirtualCell); // "virtual" cell cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); // "real" cell @@ -1443,7 +1443,7 @@ begin { Create cell } if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); diff --git a/components/fpspreadsheet/source/common/xlscommon.pas b/components/fpspreadsheet/source/common/xlscommon.pas index 10dfd208b..5149d4d7c 100644 --- a/components/fpspreadsheet/source/common/xlscommon.pas +++ b/components/fpspreadsheet/source/common/xlscommon.pas @@ -1324,7 +1324,7 @@ begin XF := WordLEToN(rec.XFIndex); if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -1359,7 +1359,7 @@ begin XF := WordLEToN(rec.XFIndex); if FIsVirtualMode then begin - InitCell(r, c, FVirtualCell); + InitCell(FWorksheet, r, c, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(r, c); @@ -1661,7 +1661,7 @@ begin { Create cell } if FIsVirtualMode then // "Virtual" cell begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.GetCell(ARow, ACol); // "Real" cell @@ -1788,7 +1788,7 @@ begin fc := WordLEtoN(AStream.ReadWord); pending := RecordSize - SizeOf(fc) - SizeOf(ARow); if FIsVirtualMode then begin - InitCell(ARow, 0, FVirtualCell); + InitCell(FWorksheet, ARow, 0, FVirtualCell); cell := @FVirtualCell; end; while pending > SizeOf(XF) do begin @@ -1832,7 +1832,7 @@ begin fc := WordLEtoN(AStream.ReadWord); pending := RecordSize - SizeOf(fc) - SizeOf(ARow); if FIsVirtualMode then begin - InitCell(ARow, fc, FVirtualCell); + InitCell(FWorksheet, ARow, fc, FVirtualCell); cell := @FVirtualCell; end; while pending > SizeOf(XF) + SizeOf(RK) do begin @@ -1894,7 +1894,7 @@ begin { Create cell } if FIsVirtualMode then begin // "virtual" cell - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); // "real" cell @@ -2185,7 +2185,7 @@ begin {Create cell} if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); + InitCell(FWorksheet, ARow, ACol, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.AddCell(ARow, ACol); @@ -2855,7 +2855,7 @@ begin { Create cell - this is the "base" of the shared formula } if FIsVirtualMode then begin // "Virtual" cell - InitCell(r1, c1, FVirtualCell); + InitCell(FWorksheet, r1, c1, FVirtualCell); cell := @FVirtualCell; end else cell := FWorksheet.GetCell(r1, c1); // "Real" cell @@ -4918,6 +4918,7 @@ begin begin lCell.Row := r; // to silence a compiler hint... InitCell(lCell); + lCell.Worksheet := ASheet; value := varNull; styleCell := nil; ASheet.OnWriteCellData(ASheet, r, c, value, styleCell); diff --git a/components/fpspreadsheet/source/common/xlsxooxml.pas b/components/fpspreadsheet/source/common/xlsxooxml.pas index c07599564..72d303a6c 100644 --- a/components/fpspreadsheet/source/common/xlsxooxml.pas +++ b/components/fpspreadsheet/source/common/xlsxooxml.pas @@ -638,7 +638,7 @@ begin // create cell if FIsVirtualMode then begin - InitCell(rowIndex, colIndex, FVirtualCell); + InitCell(FWorksheet, rowIndex, colIndex, FVirtualCell); cell := @FVirtualCell; end else cell := AWorksheet.AddCell(rowIndex, colIndex); @@ -706,7 +706,7 @@ begin begin sharedformulabase := TSharedFormulaData(FSharedFormulaBaseList[StrToInt(s)]); // ... and copy shared formula to destination cell - InitCell(sharedformulabase.Row, sharedformulabase.Col, lCell); + InitCell(FWorksheet, sharedformulabase.Row, sharedformulabase.Col, lCell); lCell.Formulavalue := sharedformulabase.Formula; lCell.Worksheet := sharedformulabase.Worksheet; FWorksheet.CopyFormula(@lCell, cell); diff --git a/components/fpspreadsheet/source/export/fpsexportreg.pas b/components/fpspreadsheet/source/export/fpsexportreg.pas index 9a7def7f6..f78ca5792 100644 --- a/components/fpspreadsheet/source/export/fpsexportreg.pas +++ b/components/fpspreadsheet/source/export/fpsexportreg.pas @@ -9,7 +9,7 @@ unit fpsexportreg; interface uses - Classes, SysUtils, LazarusPackageIntf, lresources, fpdataexporter; + Classes, SysUtils, LazarusPackageIntf, lresources; procedure Register; diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas b/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas index bb176aa40..fbdbb7f93 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas @@ -686,7 +686,7 @@ var cell: PCell; begin New(cell); - InitCell(ARow, ACol, cell^); + InitCell(nil, ARow, ACol, cell^); Result := inherited Add(cell); end; diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas index 2f2a22ca7..52ca98769 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas @@ -2131,7 +2131,6 @@ end; procedure TsCustomWorksheetGrid.DragDrop(Source: TObject; X, Y: Integer); var - i, j: Integer; sel: TsCellRange; srccell, destcell: PCell; r: LongInt = 0; @@ -2178,7 +2177,8 @@ procedure TsCustomWorksheetGrid.DragOver(ASource: TObject; X, Y: Integer; var destcell: PCell; sc, sr: Integer; - gc, gr: Integer; + gc: Integer = 0; + gr: Integer = 0; dc, dr: Integer; sel: TsCellRange; dragMove: Boolean; @@ -3014,7 +3014,6 @@ var r1,c1,r2,c2: Cardinal; delta: Integer; savedPenMode: TPenMode; - penwidth: Integer; P: array[0..9] of TPoint; begin if Worksheet = nil then