Tuesday, March 3, 2020
Working With Windows Registry From Delphi Applications
Working With Windows Registry From Delphi Applications The Registry is simply a database that an application can use to store and retrieve configuration information (last window size and position, user options and information or any other configuration data). Registry also contains information about Windows (95/98/NT) and about your Windows configuration. The Registry database is stored as a binary file. To find it, run regedit.exe (Windows registry editor utility) in your Windows directory. You will see that information in Registry is organized in a similar way to Windows Explorer. We can use regedit.exe to view registry information, change it or to add some information to it. It is obvious that modifications of the registry database could lead to a ââ¬â¹system crash (of course if you dont know what you are doing). INI vs. Registry It is probably very well known that in the days of Windows 3.xx INI files were a popular way of storing application information and other user-configurable settings. The most terrifying aspect of INI files is that they are just text files that the user can easily edit (change or even delete them). In 32-bit Windows Microsoft recommends using Registry to store the type of information that you would normally place in INI files (users are less likely to alter registry entries). Delphià provides full support for changing entries in the Windows System Registry: via the TRegIniFile class (same basic interface as the TIniFile class for users of INI files with Delphi 1.0) and TRegistry class (low-level wrapper for the Windows registry and functions that operate on the registry). Simple Tip: Writing to the Registry As mentioned before in this article, basic registry operations (using code manipulation) are reading information from ââ¬â¹Registry and writing information to the database. Next piece of code will change the Windows wallpaper and disable the screen saver using TRegistry class. Before we can use TRegistry we have to add Registry unit to the uses clause at the top of source-code. ~~~~~~~~~~~~~~~~~~~~~~~~~uses registry;procedure TForm1.FormCreate(Sender: TObject) ;varreg:TRegistry;beginreg:TRegistry.Create;with reg do begintryif OpenKey(\Control Panel\desktop, False) then begin//change wallpaper and tile itreg.WriteString (Wallpaper,c:\windows\CIRCLES.bmp) ;reg.WriteString (TileWallpaper,1) ;//disable screen saver//(0disable, 1enable)reg.WriteString(ScreenSaveActive,0) ;//update changes immediatelySystemParametersInfo (SPI_SETDESKWALLPAPER,0, nil,SPIF_SENDWININICHANGE) ;SystemParametersInfo (SPI_SETSCREENSAVEACTIVE,0, nil,SPIF_SENDWININICHANGE) ;endfinallyreg.Free;end;end;end;~~~~~~~~~~~~~~~~~~~~~~~~~ Those two lines of code that start with SystemParametersInfo ... force Windows to update the wallpaper and screen saver information immediately. When you run your application, youll see the Windows wallpaper bitmap change to the Circles.bmp image that is, if you have circles.bmp image in your Windows directory. (Note: your screen saver is now disabled.)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.