Solved

Registry

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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