whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

32 Visitors Online


 
...read and store string-values from/to the Registry?
Autor: eL pAdO
Homepage: http://www.elpado.de.vu
[ Print tip ]  

Tip Rating (3):  
     


uses
  
Registry;

function TForm1.RegRead(Mykey, MyField: string): string;
var
  
Reg: TRegistry;
begin
  
//Create the Object
  
Reg := TRegistry.Create;
  with Reg do
  begin
    
//Sets the destination for our requests
    
RootKey := HKEY_LOCAL_MACHINE;
    //Check if whe can open our key, if the key dosn't exist, we create it
    
if OpenKey(MyKey, True) then
    begin
      
//Is our field availbe
      
if ValueExists(MyField) then
        
//Read the value from the field
        
Result := Readstring(MyField)
      else
        
ShowMessage(MyField + ' does not exists under ' + MyKey);
    end
    else
      
//There is a big error if we get an errormessage by
      //opening/creating the key
      
ShowMessage('Error opening/creating key : ' + MyKey);
    CloseKey;
  end;
end;


procedure TForm1.RegWrite(Mykey, MyField, MyValue: string);
var
  
Reg: TRegistry;
begin
  
//Create the Object
  
Reg := TRegistry.Create;
  with Reg do
  begin
    
//Sets the destination for our requests
    
RootKey := HKEY_LOCAL_MACHINE;
    //Check if we can open our key, if the key doesn't exist, we create it
    
if OpenKey(MyKey, True) then
      
//We don't need to check if the field is available because the
      //field is created by writing the value
      
WriteString(MyField, MyValue)
    else
      
//There is a big error if we gets an errormessage by
      //opening/creating the key
      
ShowMessage('Error opening/creating key : ' + MyKey);
    CloseKey;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  
RegWrite('SOFTWARE\MyProgramm\', 'Path', 'C:\test.exe');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  
label1.Caption := RegRead('SOFTWARE\MyProgramm', 'Path');
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners