Registry 2time around

Everytime i do this...

reg.writestring('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',commandtobe,'1');

it appears in the registry as this:  blah\blah\blah\ noclose: "1" which is correct because i am writing a string out

BUT.... this is the problem (sorry about the points, I need to get a Credit Card)

reg.writeinteger('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',commandtobe,67108863);  {Write An Integer NOT a String}

this appears in the registry as this:  blah\blah\blah\ noclose: "67108863" which is WRONG, since that is not an integer, it appears as a string still in the registry, i need to be able to write an integer out... i am using Delphi 4.. and this is the proc i pulled it form...



procedure addlock(num: integer);
var
  commandtobe,sKey : string;
  w: hwnd;
  reg  : TRegIniFile;
begin
{key:='(Default)';}
  reg := TRegIniFile.Create( '' );
  reg.RootKey := HKEY_CURRENT_USER;
  //folder = something to store info in
  //key = key to which edit the data
  //titleofkey = data for key mame
  //commandline.....
  //HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Policies
  {reg.erasesection('Software\Microsoft\Windows\CurrentVersion\Policies\');}
  case num of
    1: commandtobe:='NoClose'; //Disable Shutdown
    2: commandtobe:='NoDrives';
    3: commandtobe:='NoNetHood';
    4: commandtobe:='NoSetFolders';
     else
    commandtobe:='NoClose';
  end;
  case num of
     1: reg.writestring('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',commandtobe,'1');
     2: reg.writeinteger('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',commandtobe,67108863);
     3: reg.writestring('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',commandtobe,'1');
     4: reg.writestring('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',commandtobe,'1');
   end;
  reg.Free;
end;


Hope Some one this time can help :)  

Thanks All... Craig C.
LVL 2
craig_capelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JoeBoothCommented:
Try making your REG variable a

TRegistry  rather  TRegIniFile

For some reason, tRegIniFile changes the method of writeInteger to write a string, while TRegistry writes the integer value.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
craig_capelAuthor Commented:
Ok i tried that method :) and guess what....

[Error] restrict1.pas(51): Too many actual parameters
[Error] restrict1.pas(52): Incompatible types: 'Integer' and 'String'
[Error] restrict1.pas(53): Too many actual parameters
[Error] restrict1.pas(54): Too many actual parameters
[Fatal Error] restrict.dpr(5): Could not compile used unit 'restrict1.pas'


what do i use instead of
 1: reg.writestring('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',commandtobe,'1');
                        2: reg.writeinteger('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',commandtobe,67108863);
                        3: reg.writestring('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',commandtobe,'1');
                        4: reg.writestring('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',commandtobe,'1');

as this is the main problem.... so instead of reg.writestring, what do i  use? i rarely never use the registry :)

Thanks Again..

Craig C.
0
craig_capelAuthor Commented:
would have been better with source code :)
0
JoeBoothCommented:
// Try these functions

procedure WriteTheInteger(const Section, Ident: string; Value: LongInt);
var
  Key, OldKey: HKEY;
begin
  Reg.CreateKey(Section);
  Key := Reg.GetKey(Section);
  if Key <> 0 then
  try
    OldKey := Reg.CurrentKey;
    Reg.SetCurrentKey(Key);
    try
      Reg.WriteInteger(Ident,Value);
    finally
      Reg.SetCurrentKey(OldKey);
    end;
  finally
    Reg.RegCloseKey(Key);
  end;
end;

procedure WriteTheString(const Section, Ident: string; Value: string);
var
  Key, OldKey: HKEY;
begin
  Reg.CreateKey(Section);
  Key := Reg.GetKey(Section);
  if Key <> 0 then
  try
    OldKey := Reg.CurrentKey;
    Reg.SetCurrentKey(Key);
    try
      Reg.WriteString(Ident,Value);
    finally
      Reg.SetCurrentKey(OldKey);
    end;
  finally
    Reg.RegCloseKey(Key);
  end;
end;

0
craig_capelAuthor Commented:
Great, but i got it already, thanks anyhow for the code and your help....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.