source: trunk/Packages/fcl-registry/regini.inc

Last change on this file was 13, checked in by chronos, 10 years ago
  • Added: Basic parsing of "Depends on" expressions.
File size: 3.8 KB
Line 
1
2{******************************************************************************
3 TRegIniFile
4 ******************************************************************************}
5
6constructor TRegIniFile.Create(const FN: String);
7begin
8 inherited Create;
9 fFileName := FN;
10 if fFileName<>'' then
11 fPath := fFileName + '\'
12 else
13 fPath := '';
14end;
15
16constructor TRegIniFile.Create(const FN: String;aaccess:longword);
17begin
18 inherited Create(aaccess);
19 fFileName := FN;
20 if fFileName<>'' then
21 fPath := fFileName + '\'
22 else
23 fPath := '';
24end;
25
26procedure TRegIniFile.DeleteKey(const Section, Ident: String);
27begin
28 if not OpenKey(fPath+Section,true) then Exit;
29 try
30 DeleteValue(Ident);
31 finally
32 CloseKey;
33 end;
34end;
35
36procedure TRegIniFile.EraseSection(const Section: string);
37begin
38 inherited DeleteKey(fPath+Section);
39end;
40
41procedure TRegIniFile.ReadSection(const Section: string; Strings: TStrings);
42begin
43 if not OpenKey(fPath+Section,false) then Exit;
44 try
45 GetValueNames(Strings);
46 finally
47 CloseKey;
48 end;
49end;
50
51procedure TRegIniFile.ReadSections(Strings: TStrings);
52begin
53 if not OpenKey(fFileName,false) then Exit;
54 try
55 GetKeyNames(Strings);
56 finally
57 CloseKey;
58 end;
59end;
60
61procedure TRegIniFile.ReadSectionValues(const Section: string; Strings: TStrings);
62var
63 ValList : TStringList;
64 V : String;
65 i : Integer;
66begin
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;
80end;
81
82procedure TRegIniFile.WriteBool(const Section, Ident: string; Value: Boolean);
83begin
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;
97end;
98
99procedure TRegIniFile.WriteInteger(const Section, Ident: string; Value: LongInt);
100begin
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;
114end;
115
116procedure TRegIniFile.WriteString(const Section, Ident, Value: String);
117begin
118 if not OpenKey(fPath+Section,true) then Exit;
119 try
120 inherited WriteString(Ident,Value);
121 finally
122 CloseKey;
123 end;
124end;
125
126function TRegIniFile.ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
127begin
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;
139end;
140
141function TRegIniFile.ReadInteger(const Section, Ident: string; Default: LongInt): LongInt;
142begin
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;
154end;
155
156function TRegIniFile.ReadString(const Section, Ident, Default: String): String;
157begin
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;
166end;
Note: See TracBrowser for help on using the repository browser.