1.下面是读写注册表的方式(读写键值是string, 用strToInt, 和 IntToStr进行转换)
function htwReadRegistry( RegKey :string Default :string MyRootKey : Hkey;
MyOpenKey :string): string
var
Registry: TRegistry;
S : string;
begin
Registry:= TRegistry.Create;
try
begin
Registry.RootKey :=MyRootKey;
// HKEY_CURRENT_USER;
Registry.OpenKey(MYOpenKey,false);
// Registry.OpenKey('/Software/MachineAdministrator',false);
S := Registry.ReadString(RegKey);
end
finally
begin
Registry.CloseKey;
Registry.Free;
end;
if Trim(S)='' then
Result := Default
else
Result := S;
end;
end;
procedure htwWriteRegistry(RegKey :string asValueTobewrited : string;
MyRootKey : Hkey;
MyOpenKey :string );
var
Registry: TRegistry;
begin
Registry:= TRegistry.Create;
try
begin
Registry.RootKey :=MyRootKey;
// HKEY_CURRENT_USER;
Registry.OpenKey(MyOpenKey,true);
//Registry.OpenKey('/Software/MachineAdministrator',true);
Registry.WriteString(RegKey,asValueTobewrited);
end
finally
begin
Registry.CloseKey;
Registry.Free;
end;
end;
end;
调用方法:
try
htwWriteRegistry('sShortDate','yyyy-MM-dd' ,HKEY_LOCAL_MACHINE, '/Control Panel/International');
htwWriteRegistry('sShortDate','yyyy-MM-dd' ,HKEY_LOCAL_MACHINE, '/.DEFAULT/Control Panel/International');
setlocaleinfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SDATE,'yyyy-MM-dd');
except
end;
///
var
sDialName :string;
try
sDialName:=htwReadRegistry('DialupName','我的连接' ,HKEY_CURRENT_USER, '/SoftWare/vgtable');
except
ShowMessage('写注册表失败');
end;