Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to read/Write A integer Dword value from registry?

Posted on 2003-03-21
4
Medium Priority
?
1,451 Views
Last Modified: 2010-04-04
Hello,

I'm trying to find a way to read and write DWORD values from registry. I know that a Dword value is a 4 bit integer but when i try to read a integer value i get an error.
If you can please give me some examples.
Thank you.
0
Comment
Question by:so3
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
emadat earned 150 total points
ID: 8185132
Here are two functions to do what you're asking for.

However; use these functions at your own risk.
They are safe in what they are doing provided that you give them the correct names and parameters.

//******************************************************************************
function GetRegDWord(KeyHandle:HKey; sKey, sName: string): DWord;
var
     Registry: TRegistry;
begin
     Registry := TRegistry.Create;
     try
          Registry.RootKey := KeyHandle;
          Registry.OpenKey(sKey, False);
          Result := Registry.ReadInteger(sName);
     finally
          Registry.Free;
     end;
end;
//******************************************************************************
procedure WriteRegDWord(KeyHandle: HKey; sKey, sName: string; dwNew: DWord);
var
     Registry: TRegistry;
begin
     Registry := TRegistry.Create;
     try
          Registry.RootKey := KeyHandle;
          Registry.OpenKey(sKey, False);
          Registry.WriteInteger(sName, dwNew);
     finally
          Registry.Free;
     end;
end;
//******************************************************************************
sKey: is the Key Name
Name: is the Value name

where Key_Handle is one of the following:
HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
HKEY_CURRENT_CONFIG

example of use:
//******************************************************************************
procedure TestRegFunctions;
var
     dwResult : DWord;
begin
     dwResult := GetRegDWord(HKEY_CURRENT_USER, 'Software\Borland\Delphi\7.0\Code Insight', 'CodeCompleteWidth');
     WriteRegDWord(HKEY_CURRENT_USER, 'Software\Borland\Delphi\7.0\Code Insight', 'TestData', 124);
end;
//******************************************************************************

Regards
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 8186682
The Delphi equivalent of a DWord is a Longword/Cardinal (unsigned 32bit).  If you try to read it into an Integer type (signed 32bit) you may get wrapping problems.
0
 
LVL 3

Expert Comment

by:emadat
ID: 8187128
If you look at the provided functions, they get it in a DWord data type; so their is no risk of conflicts regarding the sign bit.
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 8188873
Sorry, that wasnt in reply to your message
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question