You've already forked lazarus-ccr
fpspreadsheet: Fix TsWorksheet occasionally crashing in new SetCells method.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4436 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -4440,8 +4440,8 @@ end;
|
|||||||
|
|
||||||
procedure TsCustomWorksheetGrid.SetCells(ACol, ARow: Integer; AValue: Variant);
|
procedure TsCustomWorksheetGrid.SetCells(ACol, ARow: Integer; AValue: Variant);
|
||||||
var
|
var
|
||||||
cell: PCell;
|
cell: PCell = nil;
|
||||||
fmt: PsCellFormat;
|
fmt: PsCellFormat = nil;
|
||||||
nfp: TsNumFormatParams;
|
nfp: TsNumFormatParams;
|
||||||
r, c: Cardinal;
|
r, c: Cardinal;
|
||||||
s: String;
|
s: String;
|
||||||
@ -4451,52 +4451,44 @@ begin
|
|||||||
|
|
||||||
r := GetWorksheetRow(ARow);
|
r := GetWorksheetRow(ARow);
|
||||||
c := GetWorksheetCol(ACol);
|
c := GetWorksheetCol(ACol);
|
||||||
cell := Worksheet.FindCell(r, c);
|
|
||||||
if cell <> nil then begin
|
|
||||||
fmt := Workbook.GetPointerToCellFormat(cell^.FormatIndex);
|
|
||||||
if fmt <> nil then nfp := Workbook.GetNumberFormat(fmt^.NumberFormatIndex);
|
|
||||||
end else
|
|
||||||
fmt := nil;
|
|
||||||
|
|
||||||
if VarIsNull(AValue) then begin
|
// If the cell already exists and contains a formula then the formula must be
|
||||||
cell := Worksheet.WriteBlank(r, c);
|
// removed. The formula would dominate over the data value.
|
||||||
if cell <> nil then cell^.FormulaValue := '';
|
cell := Worksheet.FindCell(r, c);
|
||||||
end else
|
if HasFormula(cell) then cell^.FormulaValue := '';
|
||||||
|
|
||||||
|
if VarIsNull(AValue) then
|
||||||
|
Worksheet.WriteBlank(r, c)
|
||||||
|
else
|
||||||
if VarIsStr(AValue) then
|
if VarIsStr(AValue) then
|
||||||
begin
|
begin
|
||||||
s := VarToStr(AValue);
|
s := VarToStr(AValue);
|
||||||
if s[1] = '=' then
|
if (s <> '') and (s[1] = '=') then
|
||||||
begin
|
Worksheet.WriteFormula(r, c, Copy(s, 2, Length(s)), true)
|
||||||
Worksheet.WriteFormula(r, c, Copy(s, 2, Length(s)), true);
|
else
|
||||||
exit;
|
Worksheet.WriteText(r, c, s); // This will erase a non-formatted cell if s = ''
|
||||||
end;
|
|
||||||
Worksheet.WriteCellValueAsString(r, c, s);
|
|
||||||
cell^.FormulaValue := '';
|
|
||||||
end else
|
end else
|
||||||
begin
|
|
||||||
if cell <> nil then
|
|
||||||
cell^.FormulaValue := '';
|
|
||||||
if VarIsType(AValue, varDate) then
|
if VarIsType(AValue, varDate) then
|
||||||
Worksheet.WriteDateTime(r, c, VarToDateTime(AValue))
|
Worksheet.WriteDateTime(r, c, VarToDateTime(AValue))
|
||||||
else
|
else
|
||||||
if VarIsNumeric(AValue) then begin
|
if VarIsNumeric(AValue) then
|
||||||
if (cell <> nil) then begin
|
begin
|
||||||
if IsDateTimeFormat(nfp) then
|
// Check if the cell already exists and contains a format.
|
||||||
Worksheet.WriteDateTime(cell, VarToDateTime(AValue))
|
// If it is a date/time format write a date/time cell...
|
||||||
{
|
if cell <> nil then
|
||||||
else if IsBoolFormat(nfp) then
|
begin
|
||||||
Worksheet.WriteBoolValue(cell, not (AValue=0) )
|
fmt := Workbook.GetPointerToCellFormat(cell^.FormatIndex);
|
||||||
else if IsErrorFormat(nfp) then
|
if fmt <> nil then nfp := Workbook.GetNumberFormat(fmt^.NumberFormatIndex);
|
||||||
Worksheet.WriteErrorValue(r, c, round(AValue));
|
if (fmt <> nil) and IsDateTimeFormat(nfp) then
|
||||||
}
|
Worksheet.WriteDateTime(r, c, VarToDateTime(AValue)) else
|
||||||
|
Worksheet.WriteNumber(r, c, AValue);
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Worksheet.WriteNumber(cell, AValue);
|
// ... otherwise write a number cell
|
||||||
end else
|
|
||||||
Worksheet.WriteNumber(r, c, AValue);
|
Worksheet.WriteNumber(r, c, AValue);
|
||||||
end else
|
end else
|
||||||
if VarIsBool(AValue) then
|
if VarIsBool(AValue) then
|
||||||
Worksheet.WriteBoolValue(r, c, AValue)
|
Worksheet.WriteBoolValue(r, c, AValue);
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TsCustomWorksheetGrid.GetHorAlignment(ACol, ARow: Integer): TsHorAlignment;
|
function TsCustomWorksheetGrid.GetHorAlignment(ACol, ARow: Integer): TsHorAlignment;
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user