Solved

Registry

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

617 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