Link to home
Start Free TrialLog in
Avatar of tayto
tayto

asked on

Registry Read/Write

Hi all

I'm looking for a way to both read and write a REG_DWord value from/to the registry but without using the registry unit.
Avatar of Slavak
Slavak

You can use windows API directly. Just look help for RegOpenKey, ReqQueryValue finctions.

But I cannot see any reason why you cannot use TRegistry wrapper. Can you explain it?

One reason would be size (if making a very small file):

var res: Cardinal;
      pc: PChar;
      ph: HKEY;
begin
   try
      pc := PAnsiChar('\.txt');
      res := RegOpenKey(HKEY_CLASSES_ROOT,pc,ph);
      if res=ERROR_SUCCESS then begin
         RegSetValueEx(ph,'',0,REG_SZ,PChar(Application.ExeName),Length(Application.ExeName)+1);
         RegCloseKey(ph);
      end else begin
         MessageBox(0,PChar(SysErrorMessage(res)),'',0);
      end;
   except
      MessageBox(0,'Error while writing to regisgtry','Error',0);
   end;
end;
Avatar of tayto

ASKER

I'm making a small program for my own use and prefer not to use the registry unit in delphi unless really needed - Guess i want to do it the hard way so i can learn along the way - i've seen other routines that can access the registry without the delphi registry unit but it didn't work with the REG_DWORD type.
Avatar of tayto

ASKER

thanks ccrdude - but i want to be able to read a REG_WORD value OR write it
ASKER CERTIFIED SOLUTION
Avatar of ccrdude
ccrdude

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tayto

ASKER

Thanks ccrdude - i played around with the extra lines you gave to fit them into the routine and all works as wanted.