注册 登录
编程论坛 Delphi论坛

[求助]关于操作注册表

无知的小孩 发布于 2007-04-12 10:54, 678 次点击
请问用delphi来操作注册表,例如说存取注册表信息怎么进行啊 ?
4 回复
#2
sgliuxiu2007-04-12 12:21

给个例子给你,呵呵
procedure TMainForm.FormCreate(Sender: TObject);
var Registry: TRegistry;

begin
Registry:=TRegistry.Create;
Registry.RootKey:=HKEY_LOCAL_MACHINE;
Registry.OpenKey('\SoftWare\sgliuxiu工作室\现金收费\',True);
SysDba:=Registry.ReadString('SysDba');
SysPassWord:=Registry.ReadString('SysPassWord');
BranchName:=Registry.ReadString('BranchNo');
Programmer:=Registry.ReadString('Programmer');
TerminalNo:=Registry.ReadString('TerminalNo');
Provider1:=Registry.ReadString('Provider');
IpAdress:=Registry.ReadString('IPAddress');
RemoteServer:=Registry.ReadString('Remote Server');
DefaultDatabase1:=Registry.ReadString('DefaultDatabase');
Registry.CloseKey;
Registry.Free;
end;

#3
无知的小孩2007-04-12 12:59
可是我找不到registry
#4
sgliuxiu2007-04-12 15:49

var Registry: TRegistry; registry是自己定义的变量名啊.

delphi里面的帮助文件,你看看.

If you are writing a Windows-only application and are comfortable with the structure of the system Registry, you can use TRegistry. Unlike TRegistryIniFile, which uses the same properties and methods of other ini file components, the properties and methods of TRegistry correspond more directly to the structure of the system Registry. For example, TRegistry lets you specify both the root key and subkey, while TRegistryIniFile assumes HKEY_CURRENT_USER as a root key. In addition to methods for opening, closing, saving, moving, copying, and deleting keys, TRegistry lets you specify the access level you want to use.

Note

TRegistry is not available for cross-platform programming.

The following example retrieves a value from a registry entry:

function GetRegistryValue(KeyName: string): string;
var
Registry: TRegistry;
begin
Registry := TRegistry.Create(KEY_READ);
try
Registry.RootKey = HKEY_LOCAL_MACHINE;
// False because we do not want to create it if it doesn't exist
Registry.OpenKey(KeyName, False);
Result := Registry.ReadString('VALUE1');
finally
Registry.Free;
end;
end;

#5
无知的小孩2007-04-12 17:12
太感谢楼上了 ,好多都不懂,书上也没说清楚
这个送您,呵呵
1