source: tags/1.4.0/Forms/UFormProperty.pas

Last change on this file was 129, checked in by chronos, 2 years ago
  • Added: TVCard as TComponent descendant.
  • Modified: TContactsFile renamed to TVCardFile and moved into separate file.
File size: 4.1 KB
Line 
1unit UFormProperty;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, UVCard;
7
8type
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
40var
41 FormProperty: TFormProperty;
42
43
44implementation
45
46{$R *.lfm}
47
48uses
49 UCore;
50
51{ TFormProperty }
52
53procedure TFormProperty.ButtonOkClick(Sender: TObject);
54begin
55 SaveData;
56end;
57
58procedure TFormProperty.ComboBoxFieldChange(Sender: TObject);
59var
60 Field: TContactField;
61 Attributes: TStringList;
62 I: Integer;
63begin
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;
81end;
82
83procedure TFormProperty.EditAttributesChange(Sender: TObject);
84begin
85 UpdateField;
86end;
87
88procedure TFormProperty.EditNameChange(Sender: TObject);
89begin
90 UpdateField;
91end;
92
93procedure TFormProperty.FormClose(Sender: TObject; var CloseAction: TCloseAction);
94begin
95 Core.PersistentForm1.Save(Self);
96end;
97
98procedure TFormProperty.FormCreate(Sender: TObject);
99begin
100 Core.Translator.TranslateComponentRecursive(Self);
101 Core.ThemeManager1.UseTheme(Self);
102
103 FContactProperty := nil;
104 TContact.GetFields.LoadToStrings(ComboBoxField.Items);
105end;
106
107procedure TFormProperty.FormShow(Sender: TObject);
108begin
109 Core.PersistentForm1.Load(Self);
110end;
111
112procedure TFormProperty.UpdateField;
113var
114 Field: TContactField;
115 Groups: TStringList;
116 GroupsArray: TStringArray;
117 I: Integer;
118begin
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);
136end;
137
138procedure TFormProperty.SetContactProperty(AValue: TContactProperty);
139begin
140 if FContactProperty = AValue then Exit;
141 FContactProperty := AValue;
142 LoadData;
143end;
144
145procedure TFormProperty.LoadData;
146begin
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);
159end;
160
161procedure TFormProperty.SaveData;
162begin
163 FContactProperty.Name := EditName.Text;
164 FContactProperty.Attributes.DelimitedText := EditAttributes.Text;
165 FContactProperty.Value := EditValues.Text;
166end;
167
168end.
169
Note: See TracBrowser for help on using the repository browser.