Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Registry

Posted on 2002-04-30
4
Medium Priority
?
172 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

971 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