Solved

Registry

Posted on 2002-04-30
4
167 Views
Last Modified: 2010-04-04
How can i add a key such that it is listed after a numeral. Please see example.

If the programme sees that the string 'File1' is located in

Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon', False);

then it will write a string ('File2', 'Yes')


In general, If the programme sees that the string 'File[X]' is located in

Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon', False);

then it will write a string ('File[X+1]', 'Yes'). i wass check if the string 'File[X]' exists, if it does, then the programme will check for 'File[X+1]' to see if it has been created and will check until it finds File[Y]' that is not created and will proceed to write the data for it.
0
Comment
Question by:tyfing
4 Comments
 
LVL 5

Accepted Solution

by:
alanwhincup earned 50 total points
ID: 6981107
This should work:

uses
  ..., Registry, ...;

...

procedure TForm1.Button1Click(Sender: TObject);
var
  Reg : TRegistry;
  I : Integer;
begin
  I := 1;
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon', False) then
    begin
      while Reg.ValueExists('File' + IntToStr(I)) do
        Inc(I);
      Reg.WriteString('File' + IntToStr(I), 'Yes');
    end
    else
      ShowMessage('Key not found.');
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;

Cheers,

Alan
0
 

Author Comment

by:tyfing
ID: 6982450
what does
inc(I);
do ?
0
 
LVL 3

Expert Comment

by:hagur
ID: 6982526
inc is a function which increases a given variable by 1.

i := 1;

inc(i);

i is now 2.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6982690
Inc has an overload as well which allows you to specify an integer to increment by.  For instance, to increase a value by 10, use:

 I := 1;
 inc(I, 10).  

now I = 11

Stu :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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