source: trunk/Forms/FormProperty.pas

Last change on this file was 162, checked in by chronos, 17 months ago
  • Modified: Updated Common package.
File size: 3.7 KB
Line 
1unit FormProperty;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, VCard,
7 FormEx;
8
9type
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
41implementation
42
43{$R *.lfm}
44
45{ TFormProperty }
46
47procedure TFormProperty.ButtonOkClick(Sender: TObject);
48begin
49 SaveData;
50end;
51
52procedure TFormProperty.ComboBoxFieldChange(Sender: TObject);
53var
54 Field: TContactField;
55 Attributes: TStringList;
56 I: Integer;
57begin
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;
75end;
76
77procedure TFormProperty.EditAttributesChange(Sender: TObject);
78begin
79 UpdateField;
80end;
81
82procedure TFormProperty.EditNameChange(Sender: TObject);
83begin
84 UpdateField;
85end;
86
87procedure TFormProperty.FormCreate(Sender: TObject);
88begin
89 FContactProperty := nil;
90 TContact.GetFields.LoadToStrings(ComboBoxField.Items);
91end;
92
93procedure TFormProperty.UpdateField;
94var
95 Field: TContactField;
96 Groups: TStringList;
97 GroupsArray: TStringArray;
98 I: Integer;
99begin
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);
117end;
118
119procedure TFormProperty.SetContactProperty(AValue: TContactProperty);
120begin
121 if FContactProperty = AValue then Exit;
122 FContactProperty := AValue;
123 LoadData;
124end;
125
126procedure TFormProperty.LoadData;
127begin
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);
140end;
141
142procedure TFormProperty.SaveData;
143begin
144 FContactProperty.Name := EditName.Text;
145 FContactProperty.Attributes.DelimitedText := EditAttributes.Text;
146 FContactProperty.Value := EditValues.Text;
147end;
148
149end.
150
Note: See TracBrowser for help on using the repository browser.