📄 jclregistry.pas
字号:
if DataType in [REG_SZ, REG_EXPAND_SZ] then
try
DecimalSeparator := '.';
Result := StrToFloat(RegReadString(RootKey, Key, Name));
finally
DecimalSeparator := OldSep;
end
else
InternalGetData(RootKey, Key, Name, [REG_BINARY],
SizeOf(Result), DataType, @Result, DataSize);
end;
function RegReadDoubleDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: Double): Double;
begin
try
Result := RegReadDouble(RootKey, Key, Name);
except
Result := Def;
end;
end;
function RegReadExtended(const RootKey: DelphiHKEY; const Key, Name: string): Extended;
var
DataType, DataSize: DWORD;
OldSep: Char;
begin
RegGetDataType(RootKey, Key, Name, DataType);
OldSep := DecimalSeparator;
if DataType in [REG_SZ, REG_EXPAND_SZ] then
try
DecimalSeparator := '.';
Result := StrToFloat(RegReadString(RootKey, Key, Name));
finally
DecimalSeparator := OldSep;
end
else
InternalGetData(RootKey, Key, Name, [REG_BINARY],
SizeOf(Result), DataType, @Result, DataSize);
end;
function RegReadExtendedDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: Extended): Extended;
begin
try
Result := RegReadExtended(RootKey, Key, Name);
except
Result := Def;
end;
end;
function RegReadString(const RootKey: DelphiHKEY; const Key, Name: string): string;
begin
Result := RegReadAnsiString(RootKey, Key, Name);
end;
function RegReadStringDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: string): string;
begin
Result := RegReadAnsiStringDef(RootKey, Key, Name, Def);
end;
function RegReadAnsiString(const RootKey: DelphiHKEY; const Key, Name: AnsiString): AnsiString;
begin
Result := InternalGetString(RootKey, Key, Name, False);
end;
function RegReadAnsiStringDef(const RootKey: DelphiHKEY; const Key, Name: AnsiString; Def: AnsiString): AnsiString;
begin
try
Result := RegReadAnsiString(RootKey, Key, Name);
except
Result := Def;
end;
end;
function RegReadWideString(const RootKey: DelphiHKEY; const Key, Name: string): WideString;
begin
Result := InternalGetWideString(RootKey, Key, Name, False);
end;
function RegReadWideStringDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: WideString): WideString;
begin
try
Result := RegReadWideString(RootKey, Key, Name);
except
Result := Def;
end;
end;
procedure RegReadMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; Value: TStrings);
var
S: string;
begin
S := InternalGetString(RootKey, Key, Name, True);
MultiSzToStrings(Value, PMultiSz(PChar(S)));
end;
procedure RegReadMultiSzDef(const RootKey: DelphiHKEY; const Key, Name: string; Value, Def: TStrings);
begin
try
RegReadMultiSz(RootKey, Key, Name, Value);
except
Value.Assign(Def);
end;
end;
function RegReadMultiSz(const RootKey: DelphiHKEY; const Key, Name: string): PMultiSz;
var
S: string;
begin
S := InternalGetString(RootKey, Key, Name, True);
// always returns a newly allocated PMultiSz
Result := MultiSzDup(PMultiSz(PChar(S)));
end;
function RegReadMultiSzDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: PMultiSz): PMultiSz;
begin
try
Result := RegReadMultiSz(RootKey, Key, Name);
except
// always returns a newly allocated PMultiSz
Result := MultiSzDup(Def);
end;
end;
procedure RegReadWideMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; Value: TWideStrings);
var
S: WideString;
begin
S := InternalGetWideString(RootKey, Key, Name, True);
WideMultiSzToWideStrings(Value, PWideMultiSz(PWideChar(S)));
end;
procedure RegReadWideMultiSzDef(const RootKey: DelphiHKEY; const Key, Name: string; Value, Def: TWideStrings);
begin
try
RegReadWideMultiSz(RootKey, Key, Name, Value);
except
Value.Assign(Def);
end;
end;
function RegReadWideMultiSz(const RootKey: DelphiHKEY; const Key, Name: string): PWideMultiSz;
var
S: WideString;
begin
S := InternalGetWideString(RootKey, Key, Name, True);
// always returns a newly allocated PMultiWideSz
Result := WideMultiSzDup(PWideMultiSz(PWideChar(S)));
end;
function RegReadWideMultiSzDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: PWideMultiSz): PWideMultiSz;
begin
try
Result := RegReadWideMultiSz(RootKey, Key, Name);
except
// always returns a newly allocated PWideMultiSz
Result := WideMultiSzDup(Def);
end;
end;
function RegReadBinary(const RootKey: DelphiHKEY; const Key, Name: string; var Value;
const ValueSize: Cardinal): Cardinal;
var
DataType: DWORD;
begin
InternalGetData(RootKey, Key, Name, cRegBinKinds, ValueSize, DataType, @Value, Result);
end;
function RegReadBinaryDef(const RootKey: DelphiHKEY; const Key, Name: string;
var Value; const ValueSize: Cardinal; const Def: Byte): Cardinal;
begin
try
Result := RegReadBinary(RootKey, Key, Name, Value, ValueSize);
except
FillChar(Value, ValueSize, Def);
Result := ValueSize;
end;
end;
procedure RegWriteBool(const RootKey: DelphiHKEY; const Key, Name: string; Value: Boolean);
begin
RegWriteCardinal(RootKey, Key, Name, REG_DWORD, Cardinal(Ord(Value)));
end;
procedure RegWriteBool(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: Boolean);
begin
RegWriteCardinal(RootKey, Key, Name, DataType, Cardinal(Ord(Value)));
end;
procedure RegWriteInteger(const RootKey: DelphiHKEY; const Key, Name: string; Value: Integer);
begin
RegWriteInteger(RootKey, Key, Name, REG_DWORD, Cardinal(Value));
end;
procedure RegWriteInteger(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: Integer);
var
Val: Int64;
Size: Integer;
begin
if DataType in [REG_SZ, REG_EXPAND_SZ] then
RegWriteString(RootKey, Key, Name, DataType, Format('%d', [Value]))
else
if DataType in [REG_DWORD, REG_QWORD, REG_BINARY] then
begin
// sign extension
Val := Value;
if DataType = REG_QWORD then
Size := SizeOf(Int64)
else
Size := SizeOf(Value);
InternalSetData(RootKey, Key, Name, DataType, @Val, Size);
end
else
DataError(Key, Name);
end;
procedure RegWriteCardinal(const RootKey: DelphiHKEY; const Key, Name: string; Value: Cardinal);
begin
RegWriteCardinal(RootKey, Key, Name, REG_DWORD, Cardinal(Value));
end;
procedure RegWriteCardinal(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: Cardinal);
var
Val: Int64;
Size: Integer;
begin
if DataType in [REG_SZ, REG_EXPAND_SZ] then
RegWriteString(RootKey, Key, Name, DataType, Format('%u', [Value]))
else
if DataType in [REG_DWORD, REG_QWORD, REG_BINARY] then
begin
// no sign extension
Val := Value and $FFFFFFFF;
if DataType = REG_QWORD then
Size := SizeOf(Int64)
else
Size := SizeOf(Value);
InternalSetData(RootKey, Key, Name, DataType, @Val, Size);
end
else
DataError(Key, Name);
end;
procedure RegWriteDWORD(const RootKey: DelphiHKEY; const Key, Name: string; Value: DWORD);
begin
RegWriteCardinal(RootKey, Key, Name, REG_DWORD, Cardinal(Value));
end;
procedure RegWriteDWORD(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: DWORD);
begin
RegWriteCardinal(RootKey, Key, Name, DataType, Cardinal(Value));
end;
procedure RegWriteInt64(const RootKey: DelphiHKEY; const Key, Name: string; Value: Int64);
begin
RegWriteInt64(RootKey, Key, Name, REG_QWORD, Value);
end;
procedure RegWriteInt64(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: Int64);
begin
if DataType in [REG_SZ, REG_EXPAND_SZ] then
RegWriteString(RootKey, Key, Name, DataType, Format('%d', [Value]))
else
RegWriteUInt64(RootKey, Key, Name, DataType, UInt64(Value));
end;
procedure RegWriteUInt64(const RootKey: DelphiHKEY; const Key, Name: string; Value: UInt64);
begin
RegWriteUInt64(RootKey, Key, Name, REG_QWORD, Value);
end;
procedure RegWriteUInt64(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: UInt64);
begin
if DataType in [REG_SZ, REG_EXPAND_SZ] then
RegWriteString(RootKey, Key, Name, DataType, Format('%u', [Value]))
else
if DataType in [REG_QWORD, REG_BINARY] then
InternalSetData(RootKey, Key, Name, DataType, @Value, SizeOf(Value))
else
DataError(Key, Name);
end;
procedure RegWriteSingle(const RootKey: DelphiHKEY; const Key, Name: string; Value: Single);
begin
RegWriteSingle(RootKey, Key, Name, REG_BINARY, Value);
end;
procedure RegWriteSingle(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: Single);
begin
if DataType in [REG_SZ, REG_EXPAND_SZ] then
RegWriteString(RootKey, Key, Name, DataType, Format('%g', [Value]))
else
if DataType in [REG_BINARY] then
InternalSetData(RootKey, Key, Name, DataType, @Value, SizeOf(Value))
else
DataError(Key, Name);
end;
procedure RegWriteDouble(const RootKey: DelphiHKEY; const Key, Name: string; Value: Double);
begin
RegWriteDouble(RootKey, Key, Name, REG_BINARY, Value);
end;
procedure RegWriteDouble(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: Double);
begin
if DataType in [REG_SZ, REG_EXPAND_SZ] then
RegWriteString(RootKey, Key, Name, DataType, Format('%g', [Value]))
else
if DataType in [REG_BINARY] then
InternalSetData(RootKey, Key, Name, DataType, @Value, SizeOf(Value))
else
DataError(Key, Name);
end;
procedure RegWriteExtended(const RootKey: DelphiHKEY; const Key, Name: string; Value: Extended);
begin
RegWriteExtended(RootKey, Key, Name, REG_BINARY, Value);
end;
procedure RegWriteExtended(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: Extended);
begin
if DataType in [REG_SZ, REG_EXPAND_SZ] then
RegWriteString(RootKey, Key, Name, DataType, Format('%g', [Value]))
else
if DataType in [REG_BINARY] then
InternalSetData(RootKey, Key, Name, DataType, @Value, SizeOf(Value))
else
DataError(Key, Name);
end;
procedure RegWriteString(const RootKey: DelphiHKEY; const Key, Name, Value: string);
begin
RegWriteAnsiString(RootKey, Key, Name, REG_SZ, Value);
end;
procedure RegWriteString(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: string);
begin
RegWriteAnsiString(RootKey, Key, Name, DataType, Value);
end;
procedure RegWriteAnsiString(const RootKey: DelphiHKEY; const Key, Name, Value: AnsiString);
begin
RegWriteAnsiString(RootKey, Key, Name, REG_SZ, Value);
end;
procedure RegWriteAnsiString(const RootKey: DelphiHKEY; const Key, Name: AnsiString; DataType: Cardinal; Value: AnsiString);
begin
if DataType in [REG_BINARY, REG_SZ, REG_EXPAND_SZ] then
InternalSetData(RootKey, Key, Name, DataType, PChar(Value),
(Length(Value) + 1) * SizeOf(AnsiChar))
else
DataError(Key, Name);
end;
procedure RegWriteWideString(const RootKey: DelphiHKEY; const Key, Name: string; Value: WideString);
begin
RegWriteWideString(RootKey, Key, Name, REG_SZ, Value);
end;
procedure RegWriteWideString(const RootKey: DelphiHKEY; const Key, Name: string; DataType: Cardinal; Value: WideString);
begin
if DataType in [REG_BINARY, REG_SZ, REG_EXPAND_SZ] then
if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
InternalSetWideData(RootKey, Key, Name, REG_BINARY, PWideChar(Value),
(Length(Value) + 1) * SizeOf(WideChar))
else
InternalSetWideData(RootKey, Key, Name, DataType, PWideChar(Value),
(Length(Value) + 1) * SizeOf(WideChar))
else
DataError(Key, Name);
end;
procedure RegWriteMultiSz(const RootKey: DelphiHKEY; const Key, Name: string; Value: PMultiSz);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -