/[projects]/dao/DelphiScanner/Components/tpsystools_4.04/examples/Delphi/dbexprt0.pas
ViewVC logotype

Contents of /dao/DelphiScanner/Components/tpsystools_4.04/examples/Delphi/dbexprt0.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2671 - (show annotations) (download)
Tue Aug 25 18:15:15 2015 UTC (8 years, 9 months ago) by torben
File size: 3912 byte(s)
Added tpsystools component
1 (* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is TurboPower SysTools
15 *
16 * The Initial Developer of the Original Code is
17 * TurboPower Software
18 *
19 * Portions created by the Initial Developer are Copyright (C) 1996-2002
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * ***** END LICENSE BLOCK ***** *)
25
26 unit dbexprt0;
27
28 interface
29
30 uses
31 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
32 Db, DBTables,
33
34 StTxtDat, StExport;
35
36 type
37 TForm1 = class(TForm)
38 Memo1: TMemo;
39 Button2: TButton;
40 Button3: TButton;
41 Button4: TButton;
42 OpenDialog1: TOpenDialog;
43 Table1: TTable;
44 SaveDialog1: TSaveDialog;
45 CheckBox1: TCheckBox;
46 Button1: TButton;
47 Edit1: TEdit;
48 Label1: TLabel;
49 procedure Button1Click(Sender: TObject);
50 procedure Button2Click(Sender: TObject);
51 procedure Button3Click(Sender: TObject);
52 procedure Button4Click(Sender: TObject);
53 private
54 procedure SetCaption(const FN: string);
55 { Private declarations }
56 public
57 CurrentDb : string;
58 Exporter : TStDBtoCSVExport;
59 SchemaMaker : TStDbSchemaGenerator;
60 { Public declarations }
61 end;
62
63 var
64 Form1: TForm1;
65
66 implementation
67
68 {$R *.DFM}
69
70 const
71 DefaultCaption = 'Table Export Example';
72
73 procedure TForm1.SetCaption(const FN : string);
74 begin
75 if FN = '' then
76 Caption := DefaultCaption
77 else
78 Caption := DefaultCaption + ' - [' + FN + ']';
79 end;
80
81 procedure TForm1.Button2Click(Sender: TObject);
82 begin
83 if OpenDialog1.Execute then begin
84 Table1.Close;
85 CurrentDb := OpenDialog1.FileName;
86 Table1.TableName := CurrentDb;
87 Table1.Open;
88 SetCaption(CurrentDb);
89 end;
90 end;
91
92 procedure TForm1.Button4Click(Sender: TObject);
93 begin
94 CurrentDb := '';
95 Table1.Close;
96 Table1.TableName := CurrentDb;
97 Memo1.Lines.Clear;
98 SetCaption(CurrentDb);
99 end;
100
101 procedure TForm1.Button3Click(Sender: TObject);
102 begin
103 Exporter := TStDBtoCSVExport.Create;
104
105 try
106 Exporter.DataSet := Table1;
107 Exporter.IncludeHeader := CheckBox1.Checked;
108 Exporter.FieldDelimiter := StDeEscape(Edit1.Text);
109
110 SaveDialog1.FileName := ChangeFileExt(ExtractFileName(CurrentDb), '.csv');
111 SaveDialog1.DefaultExt := 'csv';
112 SaveDialog1.Filter := 'CSV Files (*.csv)|*.csv|All Files (*.*)|*.*';
113 SaveDialog1.Title := 'Save Table Data';
114 if SaveDialog1.Execute then begin
115 Exporter.ExportToFile(SaveDialog1.FileName);
116 Memo1.Lines.LoadFromFile(SaveDialog1.FileName);
117 end;
118
119 finally
120 Exporter.Free;
121 end;
122 end;
123
124 procedure TForm1.Button1Click(Sender: TObject);
125 begin
126 SchemaMaker := TStDbSchemaGenerator.Create;
127
128 try
129 SchemaMaker.FieldDelimiter := StDeEscape(Edit1.Text);
130
131 SchemaMaker.DataSet := Table1;
132
133 SaveDialog1.FileName := ChangeFileExt(ExtractFileName(CurrentDb), '.sch');
134 SaveDialog1.DefaultExt := 'sch';
135 SaveDialog1.Filter := 'Schema Files (*.sch)|*.sch|All Files (*.*)|*.*';
136 SaveDialog1.Title := 'Save Schema';
137 if SaveDialog1.Execute then begin
138 SchemaMaker.SchemaName := ChangeFileExt(ExtractFileName(SaveDialog1.FileName), '');
139 SchemaMaker.ExportToFile(SaveDialog1.FileName);
140 Memo1.Lines.LoadFromFile(SaveDialog1.FileName);
141 end;
142
143 finally
144 SchemaMaker.Free;
145 end;
146 end;
147
148 end.

  ViewVC Help
Powered by ViewVC 1.1.20