was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

33 Visitors Online


 
...Strings in die Registry schreiben und wieder lesen?
Autor: eL pAdO
Homepage: http://www.elpado.de.vu
[ Tip ausdrucken ]  

Tip Bewertung (5):  
     


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;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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