-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSettingsForm.pas
More file actions
114 lines (91 loc) · 2.63 KB
/
Copy pathSettingsForm.pas
File metadata and controls
114 lines (91 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
unit SettingsForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Base, AdvSmoothButton,
AdvOfficeButtons, Vcl.StdCtrls, AdvPanel, Miscellaneous;
type
TfrmSettings = class(TForm)
pnlCommon: TAdvPanel;
Label9: TLabel;
Label10: TLabel;
edtCode: TEdit;
edtName: TEdit;
chKEnabled: TAdvOfficeCheckBox;
btnSave: TAdvSmoothButton;
btnCancel: TAdvSmoothButton;
procedure btnSaveClick(Sender: TObject);
procedure chKEnabledClick(Sender: TObject);
procedure edtCodeChange(Sender: TObject);
private
{ Private declarations }
protected
SettingsID: Integer;
Group: String;
procedure ApplyChanges; virtual;
procedure SaveFields; virtual;
procedure LoadFields; virtual;
public
{ Public declarations }
function LoadForm(ID: Integer): Boolean;
end;
implementation
{$R *.dfm}
uses Data;
procedure TfrmSettings.btnSaveClick(Sender: TObject);
begin
// Save settinbgs for source to pick up
ApplyChanges;
// Save settings in memory table and then json file
with DataModule1.tblSources do begin
if FindKey([SettingsID]) then begin
Edit;
SaveFields;
Post;
SaveToFile(ExtractFilePath(Application.ExeName) + 'sources.json');
end;
end;
ModalResult := mrOK;
end;
procedure TfrmSettings.chKEnabledClick(Sender: TObject);
begin
btnSave.Enabled := True;
end;
procedure TfrmSettings.edtCodeChange(Sender: TObject);
begin
btnSave.Enabled := True;
end;
function TfrmSettings.LoadForm(ID: Integer): Boolean;
begin
SettingsID := ID;
Group := ID.ToString;
with DataModule1.tblSources do begin
if FindKey([ID]) then begin
LoadFields;
end;
end;
Caption := Caption + ' - ' + Group + ': ' + edtCode.Text + ' (' + edtName.Text + ')';
Result := ShowModal = mrOK;
end;
procedure TfrmSettings.ApplyChanges;
begin
SetSettingBoolean(Group, 'Enabled', chkEnabled.Checked);
SetGroupChangedFlag(Group, True);
end;
procedure TfrmSettings.LoadFields;
begin
with DataModule1.tblSources do begin
edtCode.Text := FieldByName('Code').AsString;
edtName.Text := FieldByName('Name').AsString;
chkEnabled.Checked := FieldByName('Enabled').AsBoolean;
end;
end;
procedure TfrmSettings.SaveFields;
begin
with DataModule1.tblSources do begin
FieldByName('Code').AsString := edtCode.Text;
FieldByName('Name').AsString := edtName.Text;
FieldByName('Enabled').AsBoolean := chkEnabled.Checked;
end;
end;
end.