1 | unit FormField;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
7 | ComCtrls, EditBtn, Spin, DbEngine, FormEx;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormField }
|
---|
12 |
|
---|
13 | TFormField = class(TFormEx)
|
---|
14 | ButtonOk: TButton;
|
---|
15 | ButtonCancel: TButton;
|
---|
16 | ComboBoxType: TComboBox;
|
---|
17 | DateEditMin: TDateEdit;
|
---|
18 | DateEditMax: TDateEdit;
|
---|
19 | EditName: TEdit;
|
---|
20 | EditStringDefault: TEdit;
|
---|
21 | EditTextBefore: TEdit;
|
---|
22 | EditTextAfter: TEdit;
|
---|
23 | FloatSpinEditMin: TFloatSpinEdit;
|
---|
24 | FloatSpinEditMax: TFloatSpinEdit;
|
---|
25 | Label1: TLabel;
|
---|
26 | Label10: TLabel;
|
---|
27 | Label11: TLabel;
|
---|
28 | Label2: TLabel;
|
---|
29 | Label3: TLabel;
|
---|
30 | Label4: TLabel;
|
---|
31 | Label5: TLabel;
|
---|
32 | Label6: TLabel;
|
---|
33 | Label7: TLabel;
|
---|
34 | Label8: TLabel;
|
---|
35 | Label9: TLabel;
|
---|
36 | PageControl1: TPageControl;
|
---|
37 | SpinEditMin: TSpinEdit;
|
---|
38 | SpinEditMax: TSpinEdit;
|
---|
39 | TabSheetFloat: TTabSheet;
|
---|
40 | TabSheetDateTime: TTabSheet;
|
---|
41 | TabSheetInteger: TTabSheet;
|
---|
42 | TabSheetString: TTabSheet;
|
---|
43 | TabSheetBoolean: TTabSheet;
|
---|
44 | procedure ComboBoxTypeChange(Sender: TObject);
|
---|
45 | procedure FormCreate(Sender: TObject);
|
---|
46 | procedure FormShow(Sender: TObject);
|
---|
47 | public
|
---|
48 | procedure Load(Field: TField);
|
---|
49 | procedure Save(Field: TField);
|
---|
50 | end;
|
---|
51 |
|
---|
52 |
|
---|
53 | implementation
|
---|
54 |
|
---|
55 | uses
|
---|
56 | DataTypes;
|
---|
57 |
|
---|
58 | {$R *.lfm}
|
---|
59 |
|
---|
60 | { TFormField }
|
---|
61 |
|
---|
62 | procedure TFormField.FormShow(Sender: TObject);
|
---|
63 | begin
|
---|
64 | end;
|
---|
65 |
|
---|
66 | procedure TFormField.FormCreate(Sender: TObject);
|
---|
67 | begin
|
---|
68 | end;
|
---|
69 |
|
---|
70 | procedure TFormField.ComboBoxTypeChange(Sender: TObject);
|
---|
71 | begin
|
---|
72 | PageControl1.TabIndex := ComboBoxType.ItemIndex;
|
---|
73 | end;
|
---|
74 |
|
---|
75 | procedure TFormField.Load(Field: TField);
|
---|
76 | var
|
---|
77 | I: Integer;
|
---|
78 | SelectedItem: TDataType;
|
---|
79 | begin
|
---|
80 | if ComboBoxType.ItemIndex <> -1 then
|
---|
81 | SelectedItem := TDataType(ComboBoxType.Items.Objects[ComboBoxType.ItemIndex])
|
---|
82 | else SelectedItem := nil;
|
---|
83 |
|
---|
84 | with Field.Table.DbClient.ConnectProfile.ClientType.DataTypes do begin
|
---|
85 | while ComboBoxType.Items.Count > Count do
|
---|
86 | ComboBoxType.Items.Delete(ComboBoxType.Items.Count - 1);
|
---|
87 | while ComboBoxType.Items.Count < Count do
|
---|
88 | ComboBoxType.Items.Add('');
|
---|
89 | for I := 0 to Count - 1 do begin
|
---|
90 | ComboBoxType.Items.Strings[I] := TDataType(Items[I]).Title;
|
---|
91 | ComboBoxType.Items.Objects[I] := Items[I];
|
---|
92 | end;
|
---|
93 | if Assigned(SelectedItem) then
|
---|
94 | ComboBoxType.ItemIndex := ComboBoxType.Items.IndexOfObject(SelectedItem);
|
---|
95 | end;
|
---|
96 |
|
---|
97 | EditName.Text := Field.Name;
|
---|
98 | EditTextAfter.Text := Field.TextAfter;
|
---|
99 | EditTextBefore.Text := Field.TextBefore;
|
---|
100 | ComboBoxType.ItemIndex := ComboBoxType.Items.IndexOfObject(Field.DataType);
|
---|
101 | ComboBoxTypeChange(Self);
|
---|
102 | case Field.DataType.FieldType of
|
---|
103 | ftString: begin
|
---|
104 | EditStringDefault.Text := TFieldString(Field.TypeRelated).DefaultValue;
|
---|
105 | end;
|
---|
106 | ftDateTime: begin
|
---|
107 | DateEditMin.Date := TFieldDateTime(Field.TypeRelated).Min;
|
---|
108 | DateEditMax.Date := TFieldDateTime(Field.TypeRelated).Max;
|
---|
109 | end;
|
---|
110 | ftInteger: begin
|
---|
111 | SpinEditMin.Value := TFieldInteger(Field.TypeRelated).Min;
|
---|
112 | SpinEditMax.Value := TFieldInteger(Field.TypeRelated).Max;
|
---|
113 | end;
|
---|
114 | ftFloat: begin
|
---|
115 | FloatSpinEditMin.Value := TFieldFloat(Field.TypeRelated).Min;
|
---|
116 | FloatSpinEditMax.Value := TFieldFloat(Field.TypeRelated).Max;
|
---|
117 | end;
|
---|
118 | end;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TFormField.Save(Field: TField);
|
---|
122 | begin
|
---|
123 | Field.Name := EditName.Text;
|
---|
124 | Field.TextBefore := EditTextBefore.Text;
|
---|
125 | Field.TextAfter := EditTextAfter.Text;
|
---|
126 | Field.DataType := TDataType(ComboBoxType.Items.Objects[ComboBoxType.ItemIndex]);
|
---|
127 | case Field.DataType.FieldType of
|
---|
128 | ftString: TFieldString(Field.TypeRelated).DefaultValue := EditStringDefault.Text;
|
---|
129 | ftDateTime: begin
|
---|
130 | TFieldDateTime(Field.TypeRelated).Min := DateEditMin.Date;
|
---|
131 | TFieldDateTime(Field.TypeRelated).Max := DateEditMax.Date;
|
---|
132 | end;
|
---|
133 | ftInteger: begin
|
---|
134 | TFieldInteger(Field.TypeRelated).Min := SpinEditMin.Value;
|
---|
135 | TFieldInteger(Field.TypeRelated).Max := SpinEditMax.Value;
|
---|
136 | end;
|
---|
137 | ftFloat: begin
|
---|
138 | TFieldFloat(Field.TypeRelated).Min := FloatSpinEditMin.Value;
|
---|
139 | TFieldFloat(Field.TypeRelated).Max := FloatSpinEditMax.Value;
|
---|
140 | end;
|
---|
141 | end;
|
---|
142 | end;
|
---|
143 |
|
---|
144 | end.
|
---|
145 |
|
---|