Important alert: (current site time 7/16/2013 5:41:01 AM EDT)
 

VB icon

Another Registry Class *updated*

Email
Submitted on: 2/26/2002 1:04:29 PM
By: leonator  
Level: Beginner
User Rating: Unrated
Compatibility: Delphi 5
Views: 10377
author picture
(About the author)
 
     Well, I've initially written this code for own purposes. Though it uses Windows and Registry Unit it makes it a lot easier to use settings stored in registry in your programs. it's similar to VB SaveSettings, but selecting Subkeys is optional. Stores data in HKEY_CURRENT_USER\Software\ (you'll have to initially define in constructor) hope this is useful =)
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
!**************************************
! Name: Another Registry Class *updated*
! Description:Well, I've initially written this code for own purposes. Though it uses Windows and Registry Unit it makes it a lot easier to use settings stored in registry in your programs. it's similar to VB SaveSettings, but selecting Subkeys is optional. Stores data in HKEY_CURRENT_USER\Software\<yourappname> (you'll have to initially define <yourappname> in constructor)
hope this is useful =)
! By: leonator
!
!This code is copyrighted and has! limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=599&lngWId=7!for details.!**************************************

unit EasyRegistry;
interface
type
 clsRegistry = object
 constructor Init(pAppname: string);
 procedure SetSubkey(pFoldername: string);
 procedure SaveRegKey(sKey, sValue: string);
 procedure SaveRegKeyInt(sKey: string; iValue: integer);
 procedure SaveRegKeyBool(sKey: string; bValue: boolean);
 function GetRegKey(sKey, sDefault: string): string;
 function GetRegKeyInt(sKey: string; iDefault: integer): integer;
 function GetRegKeyBool(sKey: string; bDefault: boolean): boolean;
 function DeleteKey(sKey: string): boolean;
 procedure DeleteSubkey;
private
 AppName: string;
 Subkey: string;
 end;
implementation
uses Windows, Registry;
var Reg: TRegistry;
constructor clsRegistry.Init(pAppname: string);
begin
 AppName := pAppname;
 Subkey := '';
end;
procedure clsRegistry.SetSubkey(pFoldername: string);
begin
 Subkey := '\' + pFoldername;
end;
procedure clsRegistry.SaveRegKey(sKey, sValue: string);
begin
 Reg := TRegistry.Create;
 try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('\Software\' + AppName + Subkey, True) then
 begin
Reg.WriteString(sKey,sValue);
Reg.CloseKey;
 end;
 finally
Reg.Free;
 end;
end;
function clsRegistry.GetRegKey(sKey, sDefault: string):string;
begin
 Reg := TRegistry.Create;
 Result := sDefault;
 try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('\Software\' + AppName + Subkey, False) then
 if Reg.ValueExists(sKey) then Result := Reg.ReadString(sKey);
 finally
Reg.Free;
 end;
end;
procedure clsRegistry.SaveRegKeyInt(sKey: string; iValue: integer);
begin
 Reg := TRegistry.Create;
 try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('\Software\' + AppName + Subkey, True) then
 begin
Reg.WriteInteger(sKey,iValue);
Reg.CloseKey;
 end;
 finally
Reg.Free;
 end;
end;
function clsRegistry.GetRegKeyInt(sKey: string; iDefault: integer): integer;
begin
 Reg := TRegistry.Create;
 Result := iDefault;
 try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('\Software\' + AppName + Subkey, False) then
 if Reg.ValueExists(sKey) then Result := Reg.ReadInteger(sKey);
 finally
Reg.Free;
 end;
end;
procedure clsRegistry.SaveRegKeyBool(sKey: string; bValue: boolean);
begin
 Reg := TRegistry.Create;
 try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('\Software\' + AppName + Subkey, True) then
 begin
Reg.WriteBool(sKey,bValue);
Reg.CloseKey;
 end;
 finally
Reg.Free;
 end;
end;
function clsRegistry.GetRegKeyBool(sKey: string; bDefault: boolean): boolean;
begin
 Reg := TRegistry.Create;
 Result := bDefault;
 try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('\Software\' + AppName + Subkey, False) then
 if Reg.ValueExists(sKey) then Result := Reg.ReadBool(sKey);
 finally
Reg.Free;
 end;
end;
function clsRegistry.DeleteKey(sKey: string): boolean;
begin
 Reg := TRegistry.Create;
 try
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('\Software\' + AppName + Subkey,False);
Result := Reg.DeleteValue(sKey)
 finally
Reg.Free;
 end;
end;
procedure clsRegistry.DeleteSubkey;
begin
 Reg := TRegistry.Create;
 try
Reg.RootKey := HKEY_CURRENT_USER;
Reg.DeleteKey('\Software\' + AppName + Subkey);
 finally
Reg.Free;
 end;
end;
end.


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

3/22/2002 8:29:31 AMleonator

sorry for the messy formating... was psc
i'm going to add simple dele key and delete subkey functions
(If this comment was disrespectful, please report it.)

 
8/12/2004 8:01:13 AMChe Guevara

thanks mate.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.