How to open a registry key using a variable?

If the function {OpenKeyReadOnly(const Key: String): Boolean;}
only accepts a constant as argument, how I can open a registry key wich name is in a variable?
brockesAsked:
Who is Participating?
 
SlaughConnect With a Mentor Commented:
I dont think it needs to be a constant..

function GetRegistryValue(KeyName: string): string;
var
  Registry: TRegistry;
begin
  Registry := TRegistry.Create(KEY_READ);
  try
    Registry.RootKey := HKEY_CURRENT_USER;
    Registry.OpenKeyReadOnly(Keyname);
    Result := Registry.ReadString('VALUE1');
  finally
    Registry.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text := GetRegistryValue('KeyName');
end;
0
All Courses

From novice to tech pro — start learning today.