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
Solved

RegSetValueEx

Posted on 1997-11-18
2
964 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

789 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