Line | |
---|
1 | unit URegistry;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Registry;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TRegistryEx = class(TRegistry)
|
---|
10 | private
|
---|
11 | public
|
---|
12 | function ReadBoolWithDefault(const Name: string;
|
---|
13 | DefaultValue: Boolean): Boolean;
|
---|
14 | function ReadIntegerWithDefault(const Name: string; DefaultValue: Integer): Integer;
|
---|
15 | function ReadStringWithDefault(const Name: string; DefaultValue: string): string;
|
---|
16 | function ReadFloatWithDefault(const Name: string;
|
---|
17 | DefaultValue: Double): Double;
|
---|
18 | end;
|
---|
19 |
|
---|
20 | implementation
|
---|
21 |
|
---|
22 | { TRegistryEx }
|
---|
23 |
|
---|
24 | function TRegistryEx.ReadIntegerWithDefault(const Name: string;
|
---|
25 | DefaultValue: Integer): Integer;
|
---|
26 | begin
|
---|
27 | if ValueExists(Name) then Result := ReadInteger(Name)
|
---|
28 | else begin
|
---|
29 | WriteInteger(Name, DefaultValue);
|
---|
30 | Result := DefaultValue;
|
---|
31 | end;
|
---|
32 | end;
|
---|
33 |
|
---|
34 | function TRegistryEx.ReadStringWithDefault(const Name: string;
|
---|
35 | DefaultValue: string): string;
|
---|
36 | begin
|
---|
37 | if ValueExists(Name) then Result := ReadString(Name)
|
---|
38 | else begin
|
---|
39 | WriteString(Name, DefaultValue);
|
---|
40 | Result := DefaultValue;
|
---|
41 | end;
|
---|
42 | end;
|
---|
43 |
|
---|
44 | function TRegistryEx.ReadFloatWithDefault(const Name: string;
|
---|
45 | DefaultValue: Double): Double;
|
---|
46 | begin
|
---|
47 | if ValueExists(Name) then Result := ReadFloat(Name)
|
---|
48 | else begin
|
---|
49 | WriteFloat(Name, DefaultValue);
|
---|
50 | Result := DefaultValue;
|
---|
51 | end;
|
---|
52 | end;
|
---|
53 |
|
---|
54 | function TRegistryEx.ReadBoolWithDefault(const Name: string;
|
---|
55 | DefaultValue: Boolean): Boolean;
|
---|
56 | begin
|
---|
57 | if ValueExists(Name) then Result := ReadBool(Name)
|
---|
58 | else begin
|
---|
59 | WriteBool(Name, DefaultValue);
|
---|
60 | Result := DefaultValue;
|
---|
61 | end;
|
---|
62 | end;
|
---|
63 |
|
---|
64 | end.
|
---|
Note:
See
TracBrowser
for help on using the repository browser.