Solved

RegSetValueEx

Posted on 1997-11-18
2
938 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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now