-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathSystem.ConfigList.pas
More file actions
150 lines (123 loc) · 3.21 KB
/
System.ConfigList.pas
File metadata and controls
150 lines (123 loc) · 3.21 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
unit System.ConfigList;
interface
uses SysUtils, Classes,System.Generics.collections,
{$ifdef FMX} FMX.Edit {$endif};
const
sConfigList_Configurou = 'Configurou';
type
TConfigListItem = class
public
Nome:String;
Valor:Variant;
ValorDefault:Variant;
Control : TComponent;
end;
TConfigListItemClassOf = class of TConfigListItem;
TConfigList = Class(TObjectList<TConfigListItem>)
private
FFileName: string;
FSessao: String;
FItemClass: TConfigListItemClassOf;
procedure SetFileName(const Value: string);
function GetItem(ANome: String): string;
procedure SetItem(ANome: String; const Value: string);
procedure SetSessao(const Value: String);
public
function ItemClass:TConfigListItemClassOf;virtual;
function add:TConfigListItem;
constructor Create(AItemClass:TConfigListItemClassOf; AFileName:string='');
procedure Gravar;
procedure Carregar;
property FileName:string read FFileName write SetFileName;
property Sessao:String read FSessao write SetSessao;
Property Item[ ANome:String ]:string read GetItem write SetItem;
end;
implementation
{ TConfigList<T> }
uses IniFiles, IniFilesEx;
function TConfigList.add: TConfigListItem;
begin
result := ItemClass.Create;
inherited add(result);
end;
procedure TConfigList.Carregar;
var it:TConfigListItem;
s:string;
begin
with TIniFile.create(FFileName) do
try
for it in self do
begin
if it.control.InheritsFrom(TEdit) then
with TEdit(it.control) do
begin
s := text;
text := ReadString('Config',it.nome,s);
end;
end;
finally
free;
end;
end;
constructor TConfigList.create(AItemClass:TConfigListItemClassOf; AFileName:string='');
begin
inherited create;
FItemClass := TConfigListItem;
if AItemClass<>nil then
FItemClass := AItemClass;
FSessao := 'Config';
FFileName := AFileName;
end;
function TConfigList.GetItem(ANome: String): string;
var it:TConfigListItem;
begin
for it in self do
if sametext(it.nome,ANome) then
begin
if it.control.InheritsFrom(TEdit) then
with TEdit(it.control) do
result := text;
exit;
end;
end;
procedure TConfigList.SetFileName(const Value: string);
begin
FFileName := Value;
end;
procedure TConfigList.SetItem(ANome: String; const Value: string);
var it:TConfigListItem;
begin
for it in self do
if sametext(it.nome,ANome) then
begin
if it.control.InheritsFrom(TEdit) then
with TEdit(it.control) do
text := Value;
exit;
end;
end;
procedure TConfigList.SetSessao(const Value: String);
begin
FSessao := Value;
end;
procedure TConfigList.Gravar;
var it:TConfigListItem;
begin
item[sConfigList_Configurou] :=DatetimeToStr(now);
with TIniFile.create(FFilename) do
try
for it in self do
begin
if it.control.InheritsFrom(TEdit) then
with TEdit(it.control) do
writeString('Config',it.nome,text);
end;
finally
free;
end;
end;
function TConfigList.ItemClass: TConfigListItemClassOf;
begin
result := FItemClass;
end;
end.