?
Solved

RegSetValueEx

Posted on 1997-11-18
2
Medium Priority
?
1,004 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

801 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