/components/dbexport/regdbexport.pp

http://github.com/graemeg/lazarus · Puppet · 169 lines · 137 code · 32 blank · 0 comment · 2 complexity · 2eb118c1d49cc751395c0d0c35b8d104 MD5 · raw file

  1. {
  2. **********************************************************************
  3. This file is part of the Free Pascal run time library.
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the license.
  6. **********************************************************************
  7. Registration of components and property editors for dbexport package.
  8. Copyright (c) 2007 by Michael Van Canneyt, member of the Free Pascal development team
  9. }
  10. unit regdbexport;
  11. {$mode objfpc}{$H+}
  12. {$IF FPC_FULLVERSION > 20500}
  13. // XMLXSDExport unit was introduced in FPC 2.5.1.
  14. {$DEFINE HASXMLXSDEXPORT}
  15. {$ENDIF}
  16. interface
  17. uses
  18. Classes, SysUtils, lresources, dbPropEdits, propedits,
  19. componenteditors, fpdataexporter, dialogs, sdb_consts;
  20. Type
  21. { TExportFieldProperty }
  22. TExportFieldProperty = class(TFieldProperty)
  23. Public
  24. procedure FillValues(const Values: TStringList); override;
  25. end;
  26. { TDataExporterComponentEditor }
  27. TDataExporterComponentEditor = class(TComponentEditor)
  28. private
  29. procedure ExecuteExporter(Ex: TFPDataExporter);
  30. public
  31. function GetVerbCount: Integer; override;
  32. function GetVerb(Index: Integer): string; override;
  33. procedure ExecuteVerb(Index: Integer); override;
  34. end;
  35. Procedure Register;
  36. implementation
  37. {$R dbexportimg.res}
  38. uses
  39. fpdbexport,
  40. fpstdExports,
  41. fpcsvexport,
  42. fpfixedexport,
  43. fpsimplexmlexport,
  44. fpsimplejsonexport,
  45. fptexexport,
  46. fpsqlexport,
  47. fprtfexport,
  48. fpdbfexport
  49. {$IFDEF HASXMLXSDEXPORT}
  50. ,fpxmlxsdexport
  51. {$ENDIF}
  52. ;
  53. { TDataExporterComponentEditor }
  54. function TDataExporterComponentEditor.GetVerbCount: Integer;
  55. begin
  56. Result:=1;
  57. end;
  58. function TDataExporterComponentEditor.GetVerb(Index: Integer): string;
  59. begin
  60. Case Index of
  61. 0: Result:=SExecute;
  62. else
  63. Result:=Inherited GetVerb(Index)
  64. end;
  65. end;
  66. procedure TDataExporterComponentEditor.ExecuteExporter(Ex : TFPDataExporter);
  67. Var
  68. B: Boolean;
  69. begin
  70. If Assigned(Ex) then
  71. If Not Assigned(Ex.Dataset) then
  72. ShowMessage(SErrNoDatasetAssigned)
  73. else
  74. begin
  75. B:=Not Ex.Dataset.Active;
  76. If B then
  77. Try
  78. Ex.Dataset.Open;
  79. except
  80. On E : Exception do
  81. begin
  82. ShowMessage(Format(SErrOpeningDataset,[E.Message]));
  83. Exit;
  84. end;
  85. end;
  86. Try
  87. Ex.Execute;
  88. Finally
  89. If B then Ex.Dataset.Close;
  90. end;
  91. end;
  92. end;
  93. procedure TDataExporterComponentEditor.ExecuteVerb(Index: Integer);
  94. begin
  95. Case Index of
  96. 0 : ExecuteExporter(GetComponent as TFPDataExporter);
  97. else
  98. Inherited
  99. end
  100. end;
  101. { TExportFieldProperty }
  102. procedure TExportFieldProperty.FillValues(const Values: TStringList);
  103. Var
  104. FI : TExportFieldItem;
  105. begin
  106. FI:=TExportFieldItem(GetComponent(0));
  107. If Assigned(FI.Exporter) and Assigned(FI.Exporter.Dataset) then
  108. FI.Exporter.Dataset.GetFieldNames(Values);
  109. end;
  110. Procedure Register;
  111. begin
  112. RegisterStdFormats;
  113. { RegisterFixedExportFormat;
  114. RegisterSQLExportFormat;
  115. RegisterSimpleXMLExportFormat;
  116. RegisterSimpleJSONExportFormat;
  117. RegisterDBFExportFormat;
  118. RegisterTexExportFormat;
  119. RegisterRTFExportFormat;
  120. Register}
  121. RegisterComponents('Data Export',[TCSVExporter,
  122. TFixedLengthExporter,
  123. TSQLExporter,
  124. {$IFDEF HASXMLXSDEXPORT}
  125. TXMLXSDExporter,
  126. {$ENDIF}
  127. TSimpleXMLExporter,
  128. TSimpleJSONExporter,
  129. TFPDBFExport,
  130. TTexExporter,
  131. TRTFExporter,
  132. TStandardExportFormats,
  133. TFPDataExporter]);
  134. RegisterPropertyEditor(TypeInfo(string), TExportFieldItem, 'FieldName', TExportFieldProperty);
  135. RegisterComponentEditor(TFPDataExporter,TDataExporterComponentEditor) ;
  136. end;
  137. end.