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>
|
<RunParams>
|
||||||
<local>
|
<local>
|
||||||
<FormatVersion Value="1"/>
|
<FormatVersion Value="1"/>
|
||||||
|
<CommandLineParams Value="D:\Prog_Lazarus\svn\lazarus-ccr\components\fpspreadsheet\examples\opendocumentdemo\test.ods"/>
|
||||||
</local>
|
</local>
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<RequiredPackages Count="2">
|
<RequiredPackages Count="2">
|
||||||
|
@ -63,7 +63,7 @@ object Form1: TForm1
|
|||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
TitleStyle = tsNative
|
TitleStyle = tsNative
|
||||||
ColWidths = (
|
ColWidths = (
|
||||||
42
|
56
|
||||||
64
|
64
|
||||||
64
|
64
|
||||||
64
|
64
|
||||||
@ -104,19 +104,19 @@ object Form1: TForm1
|
|||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
object Label1: TLabel
|
object Label1: TLabel
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 15
|
Height = 20
|
||||||
Top = 9
|
Top = 9
|
||||||
Width = 37
|
Width = 46
|
||||||
Caption = 'Sheets:'
|
Caption = 'Sheets:'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
object SheetsCombo: TComboBox
|
object SheetsCombo: TComboBox
|
||||||
Left = 72
|
Left = 72
|
||||||
Height = 23
|
Height = 28
|
||||||
Top = 4
|
Top = 4
|
||||||
Width = 808
|
Width = 808
|
||||||
Anchors = [akTop, akLeft, akRight]
|
Anchors = [akTop, akLeft, akRight]
|
||||||
ItemHeight = 15
|
ItemHeight = 20
|
||||||
ItemIndex = 0
|
ItemIndex = 0
|
||||||
Items.Strings = (
|
Items.Strings = (
|
||||||
'Sheet 1'
|
'Sheet 1'
|
||||||
|
@ -103,8 +103,13 @@ end;
|
|||||||
|
|
||||||
procedure TForm1.BtnOpenClick(Sender: TObject);
|
procedure TForm1.BtnOpenClick(Sender: TObject);
|
||||||
begin
|
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);
|
LoadFile(OpenDialog.FileName);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Saves sheet in grid to file, overwriting existing file
|
// Saves sheet in grid to file, overwriting existing file
|
||||||
@ -115,6 +120,11 @@ begin
|
|||||||
if WorksheetGrid.Workbook = nil then
|
if WorksheetGrid.Workbook = nil then
|
||||||
exit;
|
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
|
if SaveDialog.Execute then
|
||||||
begin
|
begin
|
||||||
Screen.Cursor := crHourglass;
|
Screen.Cursor := crHourglass;
|
||||||
@ -143,17 +153,28 @@ begin
|
|||||||
// Load file
|
// Load file
|
||||||
Screen.Cursor := crHourglass;
|
Screen.Cursor := crHourglass;
|
||||||
try
|
try
|
||||||
WorksheetGrid.LoadFromSpreadsheetFile(UTF8ToSys(AFileName));
|
try
|
||||||
|
WorksheetGrid.LoadFromSpreadsheetFile(UTF8ToSys(AFileName));
|
||||||
|
|
||||||
// Update user interface
|
// Update user interface
|
||||||
Caption := Format('fpsGrid - %s (%s)', [
|
Caption := Format('fpsGrid - %s (%s)', [
|
||||||
AFilename,
|
AFilename,
|
||||||
GetFileFormatName(WorksheetGrid.Workbook.FileFormat)
|
GetFileFormatName(WorksheetGrid.Workbook.FileFormat)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Collect the sheet names in the combobox for switching sheets.
|
// Collect the sheet names in the combobox for switching sheets.
|
||||||
WorksheetGrid.GetSheets(SheetsCombo.Items);
|
WorksheetGrid.GetSheets(SheetsCombo.Items);
|
||||||
SheetsCombo.ItemIndex := 0;
|
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
|
finally
|
||||||
Screen.Cursor := crDefault;
|
Screen.Cursor := crDefault;
|
||||||
|
Reference in New Issue
Block a user