📄 uregedit.pas
字号:
unit URegEdit;
interface
uses
Windows, Registry;
type
TRegEdit = class(TObject)
private
Reg: TRegistry;
ivAppName: String;
function getRootKey(): HKey;
procedure setRootKey(toKey: HKey);
procedure setAppName(toName: String);
public
constructor Create;
destructor Destroy; override;
procedure WriteSetting(Section, Value: String); overload;
procedure WriteSetting(Section: String; Value: Integer); overload;
procedure WriteSetting(Section: String; Value: Boolean); overload;
procedure DeleteSection(Section: String);
function ReadString(Section, Default: String): String;
function ReadInteger(Section: String; Default: Integer): Integer;
function ReadBoolean(Section: String; Default: Boolean): Boolean;
property RootKey: HKey Read getRootKey Write setRootKey;
property AppName: String Read ivAppName Write setAppName;
end;
implementation
constructor TRegEdit.Create;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
end;
destructor TRegEdit.Destroy;
begin
if(Length(AppName) > 0) then
begin
Reg.CloseKey;
end;
Reg.Free;
inherited Destroy;
end;
procedure TRegEdit.WriteSetting(Section, Value: String);
begin
Reg.WriteString(Section, Value);
end;
procedure TRegEdit.setRootKey(toKey: HKey);
begin
Reg.RootKey := toKey;
end;
function TRegEdit.getRootKey(): HKey;
begin
getRootKey := Reg.RootKey;
end;
procedure TRegEdit.setAppName(toName: String);
begin
if Reg.OpenKey('\Software\' + toName, True) then
begin
ivAppName := toName;
end;
end;
function TRegEdit.ReadString(Section, Default: String): String;
begin
if(Length(AppName) > 0) and Reg.ValueExists(Section) and (Reg.GetDataType(Section) = rdString) then
begin
ReadString := Reg.ReadString(Section);
end
else
begin
Result := Default;
end;
end;
procedure TRegEdit.WriteSetting(Section: String; Value: Integer);
begin
Reg.WriteInteger(Section, Value);
end;
procedure TRegEdit.WriteSetting(Section: String; Value: Boolean);
begin
Reg.WriteBool(Section, Value);
end;
function TRegEdit.ReadInteger(Section: String; Default: Integer): Integer;
begin
if(Length(AppName) > 0) and Reg.ValueExists(Section)and (Reg.GetDataType(Section) = rdInteger) then
begin
Result := Reg.ReadInteger(Section);
end
else
begin
Result := Default;
end;
end;
function TRegEdit.ReadBoolean(Section: String; Default: Boolean): Boolean;
begin
if(Length(AppName) > 0) and Reg.ValueExists(Section) and (Reg.GetDataType(Section) = rdInteger) then
begin
ReadBoolean := Reg.ReadBool(Section);
end
else
begin
Result := Default;
end;
end;
procedure TRegEdit.DeleteSection(Section: String);
begin
if(Length(AppName) > 0) and Reg.ValueExists(Section) then
begin
reg.DeleteValue(Section);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -