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