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