You've already forked lazarus-ccr
fpspreadsheet: Add error handling to fpsgrid demo.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3548 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -27,6 +27,7 @@
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<CommandLineParams Value="D:\Prog_Lazarus\svn\lazarus-ccr\components\fpspreadsheet\examples\opendocumentdemo\test.ods"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="2">
|
||||
|
@ -63,7 +63,7 @@ object Form1: TForm1
|
||||
TabOrder = 1
|
||||
TitleStyle = tsNative
|
||||
ColWidths = (
|
||||
42
|
||||
56
|
||||
64
|
||||
64
|
||||
64
|
||||
@ -104,19 +104,19 @@ object Form1: TForm1
|
||||
TabOrder = 2
|
||||
object Label1: TLabel
|
||||
Left = 8
|
||||
Height = 15
|
||||
Height = 20
|
||||
Top = 9
|
||||
Width = 37
|
||||
Width = 46
|
||||
Caption = 'Sheets:'
|
||||
ParentColor = False
|
||||
end
|
||||
object SheetsCombo: TComboBox
|
||||
Left = 72
|
||||
Height = 23
|
||||
Height = 28
|
||||
Top = 4
|
||||
Width = 808
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
ItemHeight = 15
|
||||
ItemHeight = 20
|
||||
ItemIndex = 0
|
||||
Items.Strings = (
|
||||
'Sheet 1'
|
||||
|
@ -103,8 +103,13 @@ end;
|
||||
|
||||
procedure TForm1.BtnOpenClick(Sender: TObject);
|
||||
begin
|
||||
if OpenDialog.Execute then
|
||||
if OpenDialog.FileName <> '' then begin
|
||||
OpenDialog.InitialDir := ExtractFileDir(OpenDialog.FileName);
|
||||
OpenDialog.FileName := ChangeFileExt(ExtractFileName(OpenDialog.FileName), '');
|
||||
end;
|
||||
if OpenDialog.Execute then begin
|
||||
LoadFile(OpenDialog.FileName);
|
||||
end;
|
||||
end;
|
||||
|
||||
// Saves sheet in grid to file, overwriting existing file
|
||||
@ -115,6 +120,11 @@ begin
|
||||
if WorksheetGrid.Workbook = nil then
|
||||
exit;
|
||||
|
||||
if WorksheetGrid.Workbook.Filename <>'' then begin
|
||||
SaveDialog.InitialDir := ExtractFileDir(WorksheetGrid.Workbook.FileName);
|
||||
SaveDialog.FileName := ChangeFileExt(ExtractFileName(WorksheetGrid.Workbook.FileName), '');
|
||||
end;
|
||||
|
||||
if SaveDialog.Execute then
|
||||
begin
|
||||
Screen.Cursor := crHourglass;
|
||||
@ -143,17 +153,28 @@ begin
|
||||
// Load file
|
||||
Screen.Cursor := crHourglass;
|
||||
try
|
||||
WorksheetGrid.LoadFromSpreadsheetFile(UTF8ToSys(AFileName));
|
||||
try
|
||||
WorksheetGrid.LoadFromSpreadsheetFile(UTF8ToSys(AFileName));
|
||||
|
||||
// Update user interface
|
||||
Caption := Format('fpsGrid - %s (%s)', [
|
||||
AFilename,
|
||||
GetFileFormatName(WorksheetGrid.Workbook.FileFormat)
|
||||
]);
|
||||
// Update user interface
|
||||
Caption := Format('fpsGrid - %s (%s)', [
|
||||
AFilename,
|
||||
GetFileFormatName(WorksheetGrid.Workbook.FileFormat)
|
||||
]);
|
||||
|
||||
// Collect the sheet names in the combobox for switching sheets.
|
||||
WorksheetGrid.GetSheets(SheetsCombo.Items);
|
||||
SheetsCombo.ItemIndex := 0;
|
||||
// Collect the sheet names in the combobox for switching sheets.
|
||||
WorksheetGrid.GetSheets(SheetsCombo.Items);
|
||||
SheetsCombo.ItemIndex := 0;
|
||||
except
|
||||
on E:Exception do begin
|
||||
// Empty worksheet instead of the loaded one
|
||||
WorksheetGrid.NewWorkbook(26, 100);
|
||||
Caption := 'fpsGrid - no name';
|
||||
SheetsCombo.Items.Clear;
|
||||
// Grab the error message
|
||||
WorksheetGrid.Workbook.AddErrorMsg(E.Message);
|
||||
end;
|
||||
end;
|
||||
|
||||
finally
|
||||
Screen.Cursor := crDefault;
|
||||
|
Reference in New Issue
Block a user