1 |
|
---|
2 | {******************************************************************************
|
---|
3 | TRegIniFile
|
---|
4 | ******************************************************************************}
|
---|
5 |
|
---|
6 | constructor TRegIniFile.Create(const FN: String);
|
---|
7 | begin
|
---|
8 | inherited Create;
|
---|
9 | fFileName := FN;
|
---|
10 | if fFileName<>'' then
|
---|
11 | fPath := fFileName + '\'
|
---|
12 | else
|
---|
13 | fPath := '';
|
---|
14 | end;
|
---|
15 |
|
---|
16 | constructor TRegIniFile.Create(const FN: String;aaccess:longword);
|
---|
17 | begin
|
---|
18 | inherited Create(aaccess);
|
---|
19 | fFileName := FN;
|
---|
20 | if fFileName<>'' then
|
---|
21 | fPath := fFileName + '\'
|
---|
22 | else
|
---|
23 | fPath := '';
|
---|
24 | end;
|
---|
25 |
|
---|
26 | procedure TRegIniFile.DeleteKey(const Section, Ident: String);
|
---|
27 | begin
|
---|
28 | if not OpenKey(fPath+Section,true) then Exit;
|
---|
29 | try
|
---|
30 | DeleteValue(Ident);
|
---|
31 | finally
|
---|
32 | CloseKey;
|
---|
33 | end;
|
---|
34 | end;
|
---|
35 |
|
---|
36 | procedure TRegIniFile.EraseSection(const Section: string);
|
---|
37 | begin
|
---|
38 | inherited DeleteKey(fPath+Section);
|
---|
39 | end;
|
---|
40 |
|
---|
41 | procedure TRegIniFile.ReadSection(const Section: string; Strings: TStrings);
|
---|
42 | begin
|
---|
43 | if not OpenKey(fPath+Section,false) then Exit;
|
---|
44 | try
|
---|
45 | GetValueNames(Strings);
|
---|
46 | finally
|
---|
47 | CloseKey;
|
---|
48 | end;
|
---|
49 | end;
|
---|
50 |
|
---|
51 | procedure TRegIniFile.ReadSections(Strings: TStrings);
|
---|
52 | begin
|
---|
53 | if not OpenKey(fFileName,false) then Exit;
|
---|
54 | try
|
---|
55 | GetKeyNames(Strings);
|
---|
56 | finally
|
---|
57 | CloseKey;
|
---|
58 | end;
|
---|
59 | end;
|
---|
60 |
|
---|
61 | procedure TRegIniFile.ReadSectionValues(const Section: string; Strings: TStrings);
|
---|
62 | var
|
---|
63 | ValList : TStringList;
|
---|
64 | V : String;
|
---|
65 | i : Integer;
|
---|
66 | begin
|
---|
67 | if not OpenKey(fPath+Section,false) then Exit;
|
---|
68 | ValList := TStringList.Create;
|
---|
69 | try
|
---|
70 | GetValueNames(ValList);
|
---|
71 | for i:=0 to ValList.Count-1 do
|
---|
72 | begin
|
---|
73 | V := inherited ReadString(ValList.Strings[i]);
|
---|
74 | Strings.Add(ValList.Strings[i] + '=' + V);
|
---|
75 | end;
|
---|
76 | finally
|
---|
77 | ValList.Free;
|
---|
78 | CloseKey;
|
---|
79 | end;
|
---|
80 | end;
|
---|
81 |
|
---|
82 | procedure TRegIniFile.WriteBool(const Section, Ident: string; Value: Boolean);
|
---|
83 | begin
|
---|
84 | if not OpenKey(fPath+Section,true) then Exit;
|
---|
85 | try
|
---|
86 | if not fPreferStringValues then
|
---|
87 | inherited WriteBool(Ident,Value)
|
---|
88 | else begin
|
---|
89 | if ValueExists(Ident) and (GetDataType(Ident)=rdInteger) then
|
---|
90 | inherited WriteBool(Ident,Value)
|
---|
91 | else
|
---|
92 | inherited WriteString(Ident,BoolToStr(Value));
|
---|
93 | end;
|
---|
94 | finally
|
---|
95 | CloseKey;
|
---|
96 | end;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | procedure TRegIniFile.WriteInteger(const Section, Ident: string; Value: LongInt);
|
---|
100 | begin
|
---|
101 | if not OpenKey(fPath+Section,true) then Exit;
|
---|
102 | try
|
---|
103 | if not fPreferStringValues then
|
---|
104 | inherited WriteInteger(Ident,Value)
|
---|
105 | else begin
|
---|
106 | if ValueExists(Ident) and (GetDataType(Ident)=rdInteger) then
|
---|
107 | inherited WriteInteger(Ident,Value)
|
---|
108 | else
|
---|
109 | inherited WriteString(Ident,IntToStr(Value));
|
---|
110 | end;
|
---|
111 | finally
|
---|
112 | CloseKey;
|
---|
113 | end;
|
---|
114 | end;
|
---|
115 |
|
---|
116 | procedure TRegIniFile.WriteString(const Section, Ident, Value: String);
|
---|
117 | begin
|
---|
118 | if not OpenKey(fPath+Section,true) then Exit;
|
---|
119 | try
|
---|
120 | inherited WriteString(Ident,Value);
|
---|
121 | finally
|
---|
122 | CloseKey;
|
---|
123 | end;
|
---|
124 | end;
|
---|
125 |
|
---|
126 | function TRegIniFile.ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
|
---|
127 | begin
|
---|
128 | Result := Default;
|
---|
129 | if not OpenKey(fPath+Section,false) then Exit;
|
---|
130 | try
|
---|
131 | if ValueExists(Ident) then
|
---|
132 | if (not fPreferStringValues) or (GetDataType(Ident)=rdInteger) then
|
---|
133 | Result := inherited ReadBool(Ident)
|
---|
134 | else
|
---|
135 | Result := StrToBool(inherited ReadString(Ident));
|
---|
136 | finally
|
---|
137 | CloseKey;
|
---|
138 | end;
|
---|
139 | end;
|
---|
140 |
|
---|
141 | function TRegIniFile.ReadInteger(const Section, Ident: string; Default: LongInt): LongInt;
|
---|
142 | begin
|
---|
143 | Result := Default;
|
---|
144 | if not OpenKey(fPath+Section,false) then Exit;
|
---|
145 | try
|
---|
146 | if ValueExists(Ident) then
|
---|
147 | if (not fPreferStringValues) or (GetDataType(Ident)=rdInteger) then
|
---|
148 | Result := inherited ReadInteger(Ident)
|
---|
149 | else
|
---|
150 | Result := StrToInt(inherited ReadString(Ident));
|
---|
151 | finally
|
---|
152 | CloseKey;
|
---|
153 | end;
|
---|
154 | end;
|
---|
155 |
|
---|
156 | function TRegIniFile.ReadString(const Section, Ident, Default: String): String;
|
---|
157 | begin
|
---|
158 | Result := Default;
|
---|
159 | if not OpenKey(fPath+Section,false) then Exit;
|
---|
160 | try
|
---|
161 | if ValueExists(Ident) then
|
---|
162 | Result := inherited ReadString(Ident);
|
---|
163 | finally
|
---|
164 | CloseKey;
|
---|
165 | end;
|
---|
166 | end;
|
---|