* Patch from Serge Anvarov (bug ID 35102) to reduce code duplication

git-svn-id: trunk@41952 -
This commit is contained in:
michael 2019-04-28 09:26:52 +00:00
parent a254a49e84
commit 587397253d

View File

@ -42,6 +42,17 @@ begin
Result:=(S='') or (S[1]<>'\') Result:=(S='') or (S[1]<>'\')
end; end;
function RegDataWordToRegDataType(RD: DWORD): TRegDataType;
begin
// Test in ascending because rdString is most commonly used
Result := Succ(Low(RegDataWords));
repeat
if RegDataWords[Result] = RD then
Exit;
Inc(Result);
until Result > High(Result);
Result := Low(RegDataWords);
end;
function TRegistry.sysCreateKey(Key: UnicodeString): Boolean; function TRegistry.sysCreateKey(Key: UnicodeString): Boolean;
Var Var
@ -95,9 +106,7 @@ begin
Result:=-1 Result:=-1
else else
begin begin
RegData:=High(TRegDataType); RegData:=RegDataWordToRegDataType(RD);
While (RegData>rdUnknown) and (RD<>RegDataWords[RegData]) do
RegData:=Pred(RegData);
Result:=BufSize; Result:=BufSize;
end; end;
end; end;
@ -110,15 +119,10 @@ Var
begin begin
With Value do With Value do
begin begin
FLastError:=RegQueryValueExW(fCurrentKey,PWideChar(ValueName),Nil,lpdword(@RegData),Nil,lpdword(@DataSize)); FLastError:=RegQueryValueExW(fCurrentKey,PWideChar(ValueName),Nil,@RD,Nil,lpdword(@DataSize));
Result:=FLastError=ERROR_SUCCESS; Result:=FLastError=ERROR_SUCCESS;
if Result then if Result then
begin RegData:=RegDataWordToRegDataType(RD);
RD:=DWord(RegData);
RegData:=High(TRegDataType);
While (RegData>rdUnknown) and (RD<>RegDataWords[RegData]) do
RegData:=Pred(RegData);
end;
end; end;
If Not Result Then If Not Result Then
begin begin