Advertisement
7_2009-2012 Registry #227491

Registry

The following code does two things: 1) Opens a new registry key if an existing one doesn't exist and writes to it 2) Reads the existing data in the key, and applies the data to the form using the SetBounds(); function. The code looks VERY cluttered and there is a fair bit here to put on one page, so i have uploaded a .txt version of the following code that is structured and ready to copy-and-paste!

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Firsty, you have to include the vcl\Registry.hpp header file for the compiler to reckonise the commands used in this program.
Click on the form once and double click the OnActivate event in the object inspector. Add the following code:
TRegistry& regKey = *new TRegisry();
bool keyGood = regKey.OpenKey("Software\\Test\\Test", false);
if (keyGood) {
int top = regKey.ReadInteger("Top");
int left = regKey.ReadInteger("Left");
int width = regKey.ReadInteger("Width");
int height = regKey.ReadInteger("Height");
SetBounds(left,top,width,height);
}
delete &regKey;
The above code checks for a registry key called Test. If it returns true(if it exists) then it begins reading the keys and finally sets the dimensions of the form by using the SetBounds() function. The following code must be placed in the OnClose event of the form:
TRegistry& regKey = *new TRegistry();
regKey.OpenKey("Software\\Test\\Test", true);
regKey.WriteInteger("Top", Top);
regKey.WriteInteger("Left", Left);
regKey.WriteInteger("Width", Width);
regKey.WriteInteger("Height", Height);
delete &regKey;
The above code opens a key called Test whether it exists or not and write the four dimensions of the form (width, height, top and left). The last line, delete &regKey;, simply exists the active key. Although it says delete, the key is not deleted just closed and left alone.
Original Comments (3)
Recovered from Wayback Machine