From 40e2a85bd11cdc436d98f7affd0215ced53cd9f0 Mon Sep 17 00:00:00 2001 From: bigchimp Date: Wed, 23 Jul 2014 10:47:38 +0000 Subject: [PATCH] fpspreadsheet: clean up examples: progress messages; remove win32 gui for console applications etc git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3362 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/other/test_formula_func.lpi | 6 +--- .../examples/other/test_formula_func.pas | 31 ++++++++++--------- .../examples/other/test_recursive_calc.lpi | 13 +------- .../examples/other/test_recursive_calc.pas | 18 ++++++----- .../examples/other/test_virtualmode.lpr | 12 ++++--- .../examples/other/test_write_formatting.pas | 6 +++- .../examples/other/test_write_formula.pas | 8 +++-- 7 files changed, 48 insertions(+), 46 deletions(-) diff --git a/components/fpspreadsheet/examples/other/test_formula_func.lpi b/components/fpspreadsheet/examples/other/test_formula_func.lpi index d1d9def7b..4a171014d 100644 --- a/components/fpspreadsheet/examples/other/test_formula_func.lpi +++ b/components/fpspreadsheet/examples/other/test_formula_func.lpi @@ -38,11 +38,6 @@ - - - - - @@ -65,6 +60,7 @@ + diff --git a/components/fpspreadsheet/examples/other/test_formula_func.pas b/components/fpspreadsheet/examples/other/test_formula_func.pas index ed10d0607..69140b00e 100644 --- a/components/fpspreadsheet/examples/other/test_formula_func.pas +++ b/components/fpspreadsheet/examples/other/test_formula_func.pas @@ -1,8 +1,8 @@ -{ This demo show how user-provided functions can be used for calculation of - rpn formulas that are built-in to fpspreadsheet, but don't have an own +{ This demo shows how user-provided functions can be used for calculation of + RPN formulas that are built-in to fpspreadsheet, but don't have their own calculation procedure. - The example will show implementation of the some financial formulas: + The example will show implementation of some financial formulas: - FV() (future value) - PV() (present value) - PMT() (payment) @@ -19,12 +19,13 @@ program test_formula_func; {$mode delphi}{$H+} uses - {$IFDEF UNIX}{$IFDEF UseCThreads} - cthreads, - {$ENDIF}{$ENDIF} - Classes, SysUtils, laz_fpspreadsheet - { you can add units after this }, - math, fpspreadsheet, xlsbiff8, fpsfunc, financemath; + {$IFDEF UNIX} + {$IFDEF UseCThreads} + cthreads, + {$ENDIF} + {$ENDIF} + Classes, SysUtils, + math, laz_fpspreadsheet, fpspreadsheet, xlsbiff8, fpsfunc, financemath; {------------------------------------------------------------------------------} @@ -65,6 +66,7 @@ begin end; function fpsPV(Args: TsArgumentStack; NumArgs: Integer): TsArgument; +// Present value var data: TsArgNumberArray; begin @@ -121,7 +123,6 @@ var workbook: TsWorkbook; worksheet: TsWorksheet; fval, pval, pmtval, nperval, rateval: Double; - begin { We have to register our financial functions in fpspreadsheet. Otherwise an error code would be displayed in the reading part of this demo for these @@ -326,7 +327,8 @@ begin WriteLn('Contents of file "', AFileName, '"'); WriteLn(''); - for r := 0 to worksheet.GetLastRowIndex do begin + for r := 0 to worksheet.GetLastRowIndex do + begin s1 := UTF8ToAnsi(worksheet.ReadAsUTF8Text(r, 0)); s2 := UTF8ToAnsi(worksheet.ReadAsUTF8Text(r, 1)); if s1 = '' then @@ -346,10 +348,11 @@ begin end; end; - +const + TestFile='test_fv.xls'; begin - WriteFile('test_fv.xls'); - ReadFile('test_fv.xls'); + WriteFile(TestFile); + ReadFile(TestFile); end. diff --git a/components/fpspreadsheet/examples/other/test_recursive_calc.lpi b/components/fpspreadsheet/examples/other/test_recursive_calc.lpi index ed3f81553..2c0dc8bbc 100644 --- a/components/fpspreadsheet/examples/other/test_recursive_calc.lpi +++ b/components/fpspreadsheet/examples/other/test_recursive_calc.lpi @@ -38,11 +38,6 @@ - - - - - @@ -64,6 +59,7 @@ + @@ -78,13 +74,6 @@ - - - - - - - diff --git a/components/fpspreadsheet/examples/other/test_recursive_calc.pas b/components/fpspreadsheet/examples/other/test_recursive_calc.pas index eb239ec23..7b4de2459 100644 --- a/components/fpspreadsheet/examples/other/test_recursive_calc.pas +++ b/components/fpspreadsheet/examples/other/test_recursive_calc.pas @@ -9,18 +9,21 @@ program test_recursive_calc; {$mode objfpc}{$H+} uses - {$IFDEF UNIX}{$IFDEF UseCThreads} + {$IFDEF UNIX} + {$IFDEF UseCThreads} cthreads, - {$ENDIF}{$ENDIF} - Classes, laz_fpspreadsheet - { you can add units after this }, - math, fpspreadsheet, fpsfunc; + {$ENDIF} + {$ENDIF} + Classes, + math, laz_fpspreadsheet, fpspreadsheet, fpsfunc; var workbook: TsWorkbook; worksheet: TsWorksheet; - +const + OutputFile='test_calc.xls'; begin + writeln('Starting program.'); workbook := TsWorkbook.Create; try worksheet := workbook.AddWorksheet('Calc_test'); @@ -48,7 +51,8 @@ begin // B3 worksheet.WriteNumber(2, 1, 1); - workbook.WriteToFile('test_calc.xls', sfExcel8, true); + workbook.WriteToFile(OutputFile, sfExcel8, true); + writeln('Finished. Please open "'+OutputFile+'" in your spreadsheet program.'); finally workbook.Free; end; diff --git a/components/fpspreadsheet/examples/other/test_virtualmode.lpr b/components/fpspreadsheet/examples/other/test_virtualmode.lpr index 3580c3573..04ac28698 100644 --- a/components/fpspreadsheet/examples/other/test_virtualmode.lpr +++ b/components/fpspreadsheet/examples/other/test_virtualmode.lpr @@ -3,12 +3,14 @@ program test_virtualmode; {$mode objfpc}{$H+} uses - {$IFDEF UNIX}{$IFDEF UseCThreads} + {$IFDEF UNIX} + {$IFDEF UseCThreads} cthreads, - {$ENDIF}{$ENDIF} - Classes, laz_fpspreadsheet, - { you can add units after this } lazutf8, - SysUtils, variants, fpspreadsheet, xlsbiff2, xlsbiff5, xlsbiff8, xlsxooxml; + {$ENDIF} + {$ENDIF} + Classes, SysUtils, + lazutf8, + variants, laz_fpspreadsheet, fpspreadsheet, xlsbiff2, xlsbiff5, xlsbiff8, xlsxooxml; type TDataProvider = class diff --git a/components/fpspreadsheet/examples/other/test_write_formatting.pas b/components/fpspreadsheet/examples/other/test_write_formatting.pas index 06b65f589..b0a1221e7 100644 --- a/components/fpspreadsheet/examples/other/test_write_formatting.pas +++ b/components/fpspreadsheet/examples/other/test_write_formatting.pas @@ -159,7 +159,10 @@ begin MyCell^.UsedFormattingFields := [uffBorder, uffBackgroundColor]; end; +const + TestFile='test3.odt'; begin + writeln('Starting program.'); MyDir := ExtractFilePath(ParamStr(0)); // Create the spreadsheet @@ -171,7 +174,8 @@ begin // Save the spreadsheet to a file // MyWorkbook.WriteToFile(MyDir + 'test3.xls', sfExcel8, False); - MyWorkbook.WriteToFile(MyDir + 'test3.odt', sfOpenDocument, False); + MyWorkbook.WriteToFile(MyDir + TestFile, sfOpenDocument, False); MyWorkbook.Free; + writeln('Finished. Please open "'+TestFile+'" in your spreadsheet program.'); end. diff --git a/components/fpspreadsheet/examples/other/test_write_formula.pas b/components/fpspreadsheet/examples/other/test_write_formula.pas index 83810df09..9ca45972d 100644 --- a/components/fpspreadsheet/examples/other/test_write_formula.pas +++ b/components/fpspreadsheet/examples/other/test_write_formula.pas @@ -1,7 +1,7 @@ { test_write_formula.pas -Demonstrates how to write an formula using the fpspreadsheet library +Demonstrates how to write a formula using the fpspreadsheet library AUTHORS: Felipe Monteiro de Carvalho } @@ -84,7 +84,10 @@ begin MyCell^.UsedFormattingFields := [uffBorder, uffBackgroundColor, uffBold];} end; +const + TestFile='test_formula.xls'; begin + writeln('Starting program.'); MyDir := ExtractFilePath(ParamStr(0)); // Create the spreadsheet @@ -95,8 +98,9 @@ begin WriteSecondWorksheet(); // Save the spreadsheet to a file - MyWorkbook.WriteToFile(MyDir + 'test_formula.xls', sfExcel8, True); + MyWorkbook.WriteToFile(MyDir + TestFile, sfExcel8, True); // MyWorkbook.WriteToFile(MyDir + 'test_formula.odt', sfOpenDocument, False); MyWorkbook.Free; + writeln('Finished. Please open "'+Testfile+'" in your spreadsheet program.'); end.