-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit1.pas
257 lines (232 loc) · 7.45 KB
/
unit1.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Forms, Controls, Graphics, Dialogs, Menus, ActnList, db,
dbf, SdfData, Regressi, TAGraph,
TADbSource, TASeries, Classes, TACustomSource, TAFuncSeries;
type
{ TForm1 }
TForm1 = class(TForm)
ApproximationPolynomial: TAction;
Chart1: TChart;
Chart1FuncSeries1: TFuncSeries;
Chart1LineSeries1: TLineSeries;
ChartCopy: TAction;
MenuItem6: TMenuItem;
MenuItem7: TMenuItem;
MenuItem8: TMenuItem;
ApproximationPolynomialItem: TMenuItem;
OpenDialog1: TOpenDialog;
TableOpen: TAction;
MenuItem4: TMenuItem;
MenuItem5: TMenuItem;
TableEdit: TAction;
FieldDefRemove: TAction;
FieldDefDown: TAction;
FieldDefUp: TAction;
FieldNew: TAction;
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
MenuItem3: TMenuItem;
TableNew: TAction;
ActionList1: TActionList;
DataSource1: TDataSource;
DbChartSource1: TDbChartSource;
Dbf1: TDbf;
MainMenu1: TMainMenu;
procedure ApproximationPolynomialExecute(Sender: TObject);
procedure ChartCopyExecute(Sender: TObject);
procedure FieldDefDownExecute(Sender: TObject);
procedure FieldDefRemoveExecute(Sender: TObject);
procedure FieldDefUpExecute(Sender: TObject);
procedure FieldNewExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TableEditExecute(Sender: TObject);
procedure TableNewExecute(Sender: TObject);
procedure TableOpenExecute(Sender: TObject);
private
public
PA: TPolynomialApproximator;
end;
var
Form1: TForm1;
implementation
uses CoEdFm, Patch, TblNewFm, DataInFm, dbf_common, SrcCfgFm;
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Dbf1.FilePath := BuildFileName(GetAppConfigDir(False), 'data');
OpenDialog1.InitialDir := Dbf1.FilePath;
if ForceDirectories(Dbf1.FilePath) then begin
end;
PA := TPolynomialApproximator.Create(Self);
end;
procedure TForm1.TableEditExecute(Sender: TObject);
begin
TableDataInputForm.ShowModal
end;
procedure TForm1.FieldNewExecute(Sender: TObject);
var
TypeId: PtrInt;
NewField: string;
begin
with TableNewForm do begin
TypeId := FieldTypeComboBox.ItemIndex;
NewField := FieldNameEdit.Text;
if FieldListBox.Items.IndexOfName(NewField) < 0 then
FieldListBox.Items.AddObject(Format('%s:%s', [NewField, FieldTypeComboBox.Text]), NewFieldDescription(NewField, TFieldType(TypeId), StrToInt(FieldSizeEdit.Text)))
else ShowMessageFmt('Ein Feld "%s" ist schon vorhanden', [NewField])
end;
end;
procedure TForm1.FieldDefUpExecute(Sender: TObject);
var
NewIndex: Integer;
begin
with TableNewForm.FieldListBox do begin
NewIndex := ItemIndex - 1;
Items.Move(ItemIndex, NewIndex);
ItemIndex := NewIndex;
end;
end;
procedure TForm1.FieldDefDownExecute(Sender: TObject);
var
NewIndex: Longint;
begin
with TableNewForm.FieldListBox do begin
NewIndex := ItemIndex + 1;
Items.Move(ItemIndex, NewIndex);
ItemIndex := NewIndex;
end;
end;
procedure TForm1.ChartCopyExecute(Sender: TObject);
begin
Chart1.CopyToClipboardBitmap;
end;
procedure TForm1.ApproximationPolynomialExecute(Sender: TObject);
var
i: Integer;
begin
PA.Degree := StrToInt(InputBox('Grad des Polynoms', 'Grad: ', '0'));
CoefficientEditForm.Degree := PA.Degree;
if CoefficientEditForm.ShowModal = mrOK then
with PA do begin
for i := 0 to CoefficientCount - 1 do
with CoefficientRecords[i] do begin
StartMin := StrToFloat(CoefficientEditForm.StringGrid1.Cells[1, i + 1]);
StartMax := StrToFloat(CoefficientEditForm.StringGrid1.Cells[2, i + 1])
end;
Calculate
end;
end;
procedure TForm1.FieldDefRemoveExecute(Sender: TObject);
begin
with TableNewForm.FieldListBox do begin
Items.Delete(ItemIndex);
end;
end;
procedure TForm1.TableNewExecute(Sender: TObject);
var
NoError: Boolean;
i, MaxIndex: Integer;
begin
NoError := False;
repeat
try
DBChartSource1.BeginUpdate;
if TableNewForm.ShowModal = mrOK then begin
Dbf1.Close;
if Dbf1.FieldCount > 0 then Dbf1.ClearFields;
Dbf1.FilePath := TableNewForm.DataSet.FilePath;
Dbf1.TableName := TableNewForm.DataSet.TableName;
Dbf1.FieldDefs := TableNewForm.DataSet.FieldDefs;
Dbf1.CreateTable;
repeat
try
Dbf1.Open;
TableDataInputForm.ShowModal;
Dbf1.Close;
TableEdit.Enabled := True;
with ChartSourceEditForm do begin
MaxIndex := Dbf1.FieldDefs.Count - 1;
XFieldComboBox.Items.Clear;
for i := 0 to MaxIndex do
XFieldComboBox.Items.Add(Dbf1.FieldDefs[i].Name);
YFieldComboBox.Items := XFieldComboBox.Items;
ColorFieldComboBox.Items := XFieldComboBox.Items;
TextFieldComboBox.Items := XFieldComboBox.Items;
end;
if ChartSourceEditForm.ShowModal = mrOK then begin
DBChartSource1.FieldX := ChartSourceEditForm.FieldX;
Chart1.BottomAxis.Title.Caption:= ChartSourceEditForm.FieldX;
DBChartSource1.FieldY := ChartSourceEditForm.FieldY;
Chart1.LeftAxis.Title.Caption := ChartSourceEditForm.FieldY;
DBChartSource1.FieldColor := ChartSourceEditForm.FieldColor;
DBChartSource1.FieldText := ChartSourceEditForm.FieldText;
Dbf1.Close;
Dbf1.IndexDefs.Clear;
Dbf1.Open;
Dbf1.AddIndex('X', DBChartSource1.FieldX, []);
Dbf1.IndexName := 'X';
Chart1LineSeries1.Source := DBChartSource1;
Chart1.Title.Text.Text := Dbf1.TableName;
end;
NoError := True;
except
on E: EYCountError do begin
ShowMessage(E.Message);
end;
end;
until NoError;
end;
DBChartSource1.EndUpdate;
except
on E: EDbfError do begin
ShowMessage(E.Message);
NoError := False
end;
else begin
raise;
end;
end
until NoError;
end;
procedure TForm1.TableOpenExecute(Sender: TObject);
var
i, MaxIndex: Integer;
begin
DBChartSource1.BeginUpdate;
if OpenDialog1.Execute then begin
Dbf1.Close;
Dbf1.FilePath := ExtractFilePath(OpenDialog1.FileName);
Dbf1.TableName := ExtractFileName(OpenDialog1.FileName);
Dbf1.Open;
with ChartSourceEditForm do begin
MaxIndex := Dbf1.FieldDefs.Count - 1;
XFieldComboBox.Items.Clear;
for i := 0 to MaxIndex do
XFieldComboBox.Items.Add(Dbf1.FieldDefs[i].Name);
YFieldComboBox.Items := XFieldComboBox.Items;
ColorFieldComboBox.Items := XFieldComboBox.Items;
TextFieldComboBox.Items := XFieldComboBox.Items;
end;
if ChartSourceEditForm.ShowModal = mrOK then begin
DBChartSource1.FieldX := ChartSourceEditForm.FieldX;
Chart1.BottomAxis.Title.Caption := ChartSourceEditForm.FieldX;
DBChartSource1.FieldY := ChartSourceEditForm.FieldY;
Chart1.LeftAxis.Title.Caption:= ChartSourceEditForm.FieldY;
DBChartSource1.FieldColor := ChartSourceEditForm.FieldColor;
DBChartSource1.FieldText := ChartSourceEditForm.FieldText;
Dbf1.IndexDefs.Clear;
Dbf1.Open;
Dbf1.AddIndex('X', DBChartSource1.FieldX, []);
Dbf1.IndexName := 'X';
Chart1LineSeries1.Source := DbChartSource1;
Chart1.Title.Text.Text := Dbf1.TableName;
TableEdit.Enabled := True;
end;
end;
DBChartSource1.EndUpdate;
end;
end.