stringlistcontainer StoreToRegistry method
Return to Introduction  Previous page  Next page
Applies to
acStringListContainer component.  

Declaration
procedure StoreToRegistry(Reg: TRegistry); overload;  
procedure StoreToRegistry(const KeyName: Stringconst RootKey: hKey = HKEY_CURRENT_USER); overload;  

Description
The StoreToRegistry method saves all content of the string list to the registry.  
 
There is 2 overloaded methods of calling the StoreToRegisty:  
1. The registry key must be previously opened and handle to TRegistry object must be passed with Reg parameter (see first example below);  
2. You must pass the KeyName and the RootKey (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE) as parameters (see second example below).  

Screenshot from RegEdit (demonstrates how the values can be stored to registry)
acstringlistcontainerregss  

Example 1 (if the TRegistry object already prepared before saving of the strings)
uses Registry;  
 
procedure TForm1.Button1Click(Sender: TObject);  
var  
  MyKey: String;  
  Reg: TRegistry;  
begin  
  MyKey := 'SOFTWARE\My Company Name\My Program Name\StringList';  
 
  Reg := TRegistry.Create;  
  with Reg do  
   try  
     RootKey := HKEY_CURRENT_USER;  
     DeleteKey(MyKey); // delete old values from that registry key before store new  
     if OpenKey(MyKey, True) then  
       acStringListContainer1.StoreToRegistry(Reg);  
   finally  
     Free;  
   end;  
end;  

Example 2 (if we want to pass the KeyName and RootKey as parameters without preparing of the TRegistry object)
procedure TForm1.Button1Click(Sender: TObject);  
begin  
  acStringListContainer1.StoreToRegistry('SOFTWARE\My Company Name\My Program Name\StringList');  
end;  

See also
LoadFromRegistry, SaveToFile and LoadFromFile methods;  
Strings, Names, Values, MaxSize and Duplicates properties.