Ada 编程/库/GNAT.Registry
外观
该软件包提供对 Windows 注册表的较高层绑定。可以执行一些简单操作,例如读取键值和创建新键。此绑定仅处理类型为 Standard.String 的键值。有关完整的注册表 API(但处于较低抽象级别),请参阅 Win32Ada 绑定提供的 Win32.Winreg 软件包。
使用此软件包的示例
with GNAT.registry;
with Ada.Text_IO;
with Ada.Exceptions;
with Ada.Strings.Unbounded;
use GNAT.registry;
use Ada.Text_IO;
use Ada.Exceptions;
use Ada.Strings.Unbounded;
-- This is an example of how to manipulate the windows registry using
-- the GNAT.registry class. It reads in the value of a key if it exists,
-- otherwise, it creates a new key, modifies its value, and then removes the key.
procedure Registry_Manip is
reg : HKEY;
key : String := "SOFTWARE\Raytheon";
subKey : String := "URL";
subKeyValue : String := "http://www.raytheon.com";
currentValue : Unbounded_String;
begin
Put_Line("Creating registry key: " & key);
reg := Create_Key(HKEY_CURRENT_USER, key);
Put_Line("Testing to see if key already exists (key_exists() doesn't work)");
begin
currentValue := To_Unbounded_String(Query_Value(reg, subKey));
exception
when Registry_Error =>
currentValue := To_Unbounded_String(""); --No Key Found
end;
if (currentValue /= "") then
Put_Line("Key Exists! Value: " & To_String(currentValue));
else
Put_Line("Key does not Exist.");
end if;
Put_Line("Added registry sub-key: " & subKey);
Put_Line(" with a value of: " & subKeyValue);
Set_Value(reg, subKey, subKeyValue);
-- Put_Line("Deleting registry sub-key: " & subKey);
-- Delete_Value(reg, subKey);
-- Put_Line("Deleting registry key: " & key);
-- Delete_Key(HKEY_CURRENT_USER, key);
Put_Line("Closing the key");
Close_Key(reg);
-- This will catch all Registry_Error exceptions that may be thrown
exception
when E : others =>
Put_Line(Exception_Name (E) & ": " & Exception_Message (E));
end Registry_Manip;