Search code examples
delphiregistrydelphi-xe2

Accessing the registry key having Quotation Mark


I want to open a registry key in the format XXX'XX from Delphi XE2

Rootpath := '\SOFTWARE\XXXX XXXX\XXXXX''XXX\XXX';
Reg.OpenKey(Rootpath, FALSE);

Since Delphi escape character for ' is '' I cannot able to open the registry.

Looking for your help. Thanks in Advance.


Solution

  • Escaping the single quote with '' in a string works perfectly well. The resulting string contains a single character. That's the whole point of escaping it. To convince yourself of this try writing such a string to the console, or showing it in a message box.

    {$APPTYPE CONSOLE}
    begin
      Writeln('XXX''XXX');
    end.
    

    This program outputs:

    XXX'XXX
    

    The reality is that your problem is elsewhere. Possible reasons include:

    • You got the path wrong, or
    • you did not account for registry redirection, or
    • your user does not have sufficient privileges to open the key with the rights you requested.