PageRenderTime 22ms CodeModel.GetById 11ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/components/dbexport/regdbexport.pp

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