?
Solved

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

Posted on 2003-03-21
4
Medium Priority
?
1,298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 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