1 | unit UFormProperty;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, UVCard;
|
---|
7 |
|
---|
8 | type
|
---|
9 |
|
---|
10 | { TFormProperty }
|
---|
11 |
|
---|
12 | TFormProperty = class(TForm)
|
---|
13 | ButtonCancel: TButton;
|
---|
14 | ButtonOk: TButton;
|
---|
15 | ComboBoxField: TComboBox;
|
---|
16 | EditName: TEdit;
|
---|
17 | EditAttributes: TEdit;
|
---|
18 | EditValues: TEdit;
|
---|
19 | Label1: TLabel;
|
---|
20 | Label2: TLabel;
|
---|
21 | Label3: TLabel;
|
---|
22 | Label4: TLabel;
|
---|
23 | procedure ButtonOkClick(Sender: TObject);
|
---|
24 | procedure ComboBoxFieldChange(Sender: TObject);
|
---|
25 | procedure EditAttributesChange(Sender: TObject);
|
---|
26 | procedure EditNameChange(Sender: TObject);
|
---|
27 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
28 | procedure FormCreate(Sender: TObject);
|
---|
29 | procedure FormShow(Sender: TObject);
|
---|
30 | private
|
---|
31 | FContactProperty: TContactProperty;
|
---|
32 | procedure UpdateField;
|
---|
33 | procedure SetContactProperty(AValue: TContactProperty);
|
---|
34 | procedure LoadData;
|
---|
35 | procedure SaveData;
|
---|
36 | public
|
---|
37 | property ContactProperty: TContactProperty read FContactProperty write SetContactProperty;
|
---|
38 | end;
|
---|
39 |
|
---|
40 | var
|
---|
41 | FormProperty: TFormProperty;
|
---|
42 |
|
---|
43 |
|
---|
44 | implementation
|
---|
45 |
|
---|
46 | {$R *.lfm}
|
---|
47 |
|
---|
48 | uses
|
---|
49 | UCore;
|
---|
50 |
|
---|
51 | { TFormProperty }
|
---|
52 |
|
---|
53 | procedure TFormProperty.ButtonOkClick(Sender: TObject);
|
---|
54 | begin
|
---|
55 | SaveData;
|
---|
56 | end;
|
---|
57 |
|
---|
58 | procedure TFormProperty.ComboBoxFieldChange(Sender: TObject);
|
---|
59 | var
|
---|
60 | Field: TContactField;
|
---|
61 | Attributes: TStringList;
|
---|
62 | I: Integer;
|
---|
63 | begin
|
---|
64 | if ComboBoxField.ItemIndex <> -1 then begin
|
---|
65 | Field := TContactField(ComboBoxField.Items.Objects[ComboBoxField.ItemIndex]);
|
---|
66 | if Assigned(Field) then begin
|
---|
67 | EditName.Text := Field.SysName;
|
---|
68 | Attributes := TStringList.Create;
|
---|
69 | try
|
---|
70 | Attributes.NameValueSeparator := '=';
|
---|
71 | Attributes.Delimiter := ';';
|
---|
72 | Attributes.StrictDelimiter := True;
|
---|
73 | for I := 0 to Length(Field.Groups) - 1 do
|
---|
74 | Attributes.Add(Field.Groups[I]);
|
---|
75 | EditAttributes.Text := Attributes.DelimitedText;
|
---|
76 | finally
|
---|
77 | Attributes.Free;
|
---|
78 | end;
|
---|
79 | end;
|
---|
80 | end;
|
---|
81 | end;
|
---|
82 |
|
---|
83 | procedure TFormProperty.EditAttributesChange(Sender: TObject);
|
---|
84 | begin
|
---|
85 | UpdateField;
|
---|
86 | end;
|
---|
87 |
|
---|
88 | procedure TFormProperty.EditNameChange(Sender: TObject);
|
---|
89 | begin
|
---|
90 | UpdateField;
|
---|
91 | end;
|
---|
92 |
|
---|
93 | procedure TFormProperty.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
94 | begin
|
---|
95 | Core.PersistentForm1.Save(Self);
|
---|
96 | end;
|
---|
97 |
|
---|
98 | procedure TFormProperty.FormCreate(Sender: TObject);
|
---|
99 | begin
|
---|
100 | Core.Translator.TranslateComponentRecursive(Self);
|
---|
101 | Core.ThemeManager1.UseTheme(Self);
|
---|
102 |
|
---|
103 | FContactProperty := nil;
|
---|
104 | TContact.GetFields.LoadToStrings(ComboBoxField.Items);
|
---|
105 | end;
|
---|
106 |
|
---|
107 | procedure TFormProperty.FormShow(Sender: TObject);
|
---|
108 | begin
|
---|
109 | Core.PersistentForm1.Load(Self);
|
---|
110 | end;
|
---|
111 |
|
---|
112 | procedure TFormProperty.UpdateField;
|
---|
113 | var
|
---|
114 | Field: TContactField;
|
---|
115 | Groups: TStringList;
|
---|
116 | GroupsArray: TStringArray;
|
---|
117 | I: Integer;
|
---|
118 | begin
|
---|
119 | Groups := TStringList.Create;
|
---|
120 | try
|
---|
121 | Groups.NameValueSeparator := '=';
|
---|
122 | Groups.Delimiter := ';';
|
---|
123 | Groups.StrictDelimiter := True;
|
---|
124 | Groups.DelimitedText := EditAttributes.Text;
|
---|
125 | GroupsArray := Default(TStringArray);
|
---|
126 | SetLength(GroupsArray, Groups.Count);
|
---|
127 | for I := 0 to Groups.Count - 1 do
|
---|
128 | GroupsArray[I] := Groups[I];
|
---|
129 | finally
|
---|
130 | Groups.Free;
|
---|
131 | end;
|
---|
132 | Field := TContact.GetFields.GetBySysNameGroups(EditName.Text,
|
---|
133 | GroupsArray);
|
---|
134 | if Assigned(Field) then
|
---|
135 | ComboBoxField.ItemIndex := ComboBoxField.Items.IndexOfObject(Field);
|
---|
136 | end;
|
---|
137 |
|
---|
138 | procedure TFormProperty.SetContactProperty(AValue: TContactProperty);
|
---|
139 | begin
|
---|
140 | if FContactProperty = AValue then Exit;
|
---|
141 | FContactProperty := AValue;
|
---|
142 | LoadData;
|
---|
143 | end;
|
---|
144 |
|
---|
145 | procedure TFormProperty.LoadData;
|
---|
146 | begin
|
---|
147 | if Assigned(FContactProperty) then begin
|
---|
148 | EditName.Text := FContactProperty.Name;
|
---|
149 | EditAttributes.Text := FContactProperty.Attributes.DelimitedText;
|
---|
150 | EditValues.Text := FContactProperty.Value;
|
---|
151 | end else begin
|
---|
152 | EditName.Text := '';
|
---|
153 | EditAttributes.Text := '';
|
---|
154 | EditValues.Text := '';
|
---|
155 | end;
|
---|
156 | EditName.Enabled := Assigned(FContactProperty);
|
---|
157 | EditAttributes.Enabled := Assigned(FContactProperty);
|
---|
158 | EditValues.Enabled := Assigned(FContactProperty);
|
---|
159 | end;
|
---|
160 |
|
---|
161 | procedure TFormProperty.SaveData;
|
---|
162 | begin
|
---|
163 | FContactProperty.Name := EditName.Text;
|
---|
164 | FContactProperty.Attributes.DelimitedText := EditAttributes.Text;
|
---|
165 | FContactProperty.Value := EditValues.Text;
|
---|
166 | end;
|
---|
167 |
|
---|
168 | end.
|
---|
169 |
|
---|