fpreportdatadbf.pp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2022 by Michael van Canneyt and other members of the
  4. Free Pascal development team
  5. report data dbf
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit fpreportdatadbf;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. {$mode objfpc}{$H+}
  16. interface
  17. {$IFDEF FPC_DOTTEDUNITS}
  18. uses
  19. System.Classes, System.SysUtils, Data.Db, Data.Dbf.Dbf, FpJson.Data, FpReport.Data;
  20. {$ELSE FPC_DOTTEDUNITS}
  21. uses
  22. Classes, SysUtils, db, dbf, fpjson, fpreportdata;
  23. {$ENDIF FPC_DOTTEDUNITS}
  24. Const
  25. keyFileName = 'filename';
  26. Type
  27. TDBFReportDataHandler = Class(TFPReportDataHandler)
  28. Function CreateDataset(AOwner : TComponent; AConfig : TJSONObject) : TDataset; override;
  29. Class Function CheckConfig(AConfig: TJSONObject): String; override;
  30. Class Function DataType : String; override;
  31. Class Function DataTypeDescription : String; override;
  32. end;
  33. Resourcestring
  34. SErrNeedFileName = 'Need a DBF file name';
  35. SFileNameDoesNotExist = 'Filename does not exist: "%s"';
  36. implementation
  37. function TDBFReportDataHandler.CreateDataset(AOwner: TComponent; AConfig: TJSONObject): TDataset;
  38. Var
  39. C : TDBF;
  40. begin
  41. C:=TDBF.Create(AOWner);
  42. C.TableName:=AConfig.Get(KeyFileName,'');
  43. C.ReadOnly:=True;
  44. Result:=C;
  45. end;
  46. class function TDBFReportDataHandler.CheckConfig(AConfig: TJSONObject): String;
  47. Var
  48. FN : UTF8String;
  49. begin
  50. Result:='';
  51. FN:=AConfig.Get(KeyFileName,'');
  52. if FN='' then
  53. Result:=SErrNeedFileName
  54. else if not FileExists(FN) then
  55. Result:=Format(SFileNameDoesNotExist,[FN]);
  56. end;
  57. class function TDBFReportDataHandler.DataType: String;
  58. begin
  59. Result:='DBF'
  60. end;
  61. class function TDBFReportDataHandler.DataTypeDescription: String;
  62. begin
  63. Result:='DBase data file';
  64. end;
  65. initialization
  66. TDBFReportDataHandler.RegisterHandler;
  67. end.