Solved

RegSetValueEx

Posted on 1997-11-18
2
980 Views
Last Modified: 2012-11-30
Eeeehm,I last time asked how to use Regqueryvalueex. Now I know and it works just great. Now I want to use RegSetValueEx and can't work that one out. Could someone explain to me the datatypes used and give a little example?
(I'm afraid my 4GL background lacks this sort of knowledge.)
0
Comment
Question by:lizzzard
[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 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 50 total points
ID: 1350840
Hi

The most common types of data are strings (REG_SZ), Numbers (REG_DWORD) and Binary Data (REG_BINARY).  Here is an example using those 3 types:

procedure TForm1.Button1Click(Sender: TObject);
var
  hReg, TestInt: Integer;
  TestStr: string;
  TestBin: array[0..100] of Byte;
begin
  // Open or Create the registry key.
  if (RegOpenKey(HKEY_CURRENT_USER, 'Software\TestComp\TestApp', hReg) <> ERROR_SUCCESS) then
    RegCreateKey(HKEY_CURRENT_USER, 'Software\TestComp\TestApp', hReg);

  // Write a string value.
  TestStr := 'This is a test value.';
  RegSetValueEx(hReg, PChar('Test String'), 0, REG_SZ, PChar(TestStr), Length(TestStr));

  // Write an integer value.
  TestInt := 100;
  RegSetValueEx(hReg, PChar('Test Int'), 0, REG_DWORD, @TestInt, SizeOf(DWORD));

  // Write some binary data.
  FillChar(TestBin, SizeOf(TestBin), 0);
  RegSetValueEx(hReg, PChar('Test Binary'), 0, REG_BINARY, @TestBin, SizeOf(TestBin));

  // Close the registry key.
  RegCloseKey(hReg);
end;

Note that often numbers are stored as strings using Delphi's IntToStr and StrToInt functions.

Regards,
JB
0
 

Expert Comment

by:dkep
ID: 38648432
Also I believe it is the best practice to call the RegFlushKey() function prior to closing the registry key (I.E. RegCloseKey())
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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