Solved

Registry

Posted on 2002-04-30
4
164 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

20 Experts available now in Live!

Get 1:1 Help Now