Lire/Ecrire un string dans la base de registre

Uses registry;

Function TForm1.RegRead (Mykey,MyField : String) : string;
begin
//Create the Object
with (TRegistry.Create) 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);
end;
end;


Procedure TForm1.RegWrite (Mykey,MyField,MyValue : String);
begin
//Create the Object
with (TRegistry.Create) 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);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
RegWrite('SOFTWAREMyProgramm','Path','C: est.exe');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Label1.Caption := RegRead('SOFTWAREMyProgramm','Path');
end;
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour28/11/2001
VisualisationVu 996 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Systeme
Auteur de l'article
SwissDelphiCenter SwissDelphiCenter
connecté le 02/11/2011
329 articles dans la section
Contacter l'auteur