Mega Code Archive

 
Categories / Delphi / Examples
 

Registry

procedure WriteStringReg (const Key,Name,Value: string); begin procedure TIniOut.LoadFromRegistry; var Reg : TRegistry; A : Integer; Section : String; Ident : String; begin Reg := TRegistry.Create; try case RegistryRoot of CLASSES_ROOT : Reg.RootKey := HKEY_CLASSES_ROOT; DYN_DATA : Reg.RootKey := HKEY_DYN_DATA; end; for A := 0 to Items.Count-1 do begin S1 := Items[A]; if not IsValid(S1) then continue; Section := Parse(S1,ppSection,';'); Ident := Parse(S1,ppIdent,';'); try Reg.CloseKey; if Reg.OpenKey(Section,False) then if Reg.ValueExists(Ident) then DoStuff; except end; end; finally Reg.Free; end; end; procedure TIniOut.SaveToRegistry; var Reg : TRegistry; A : Integer; TmpCmp : TComponent; PropInfo : PPropInfo; S1 : String; CmpName : String; PrpName : String; Section : String; Ident : String; begin TheForm := (Owner as TForm); Reg := TRegistry.Create; try case RegistryRoot of CLASSES_ROOT : Reg.RootKey := HKEY_CLASSES_ROOT; CURRENT_USER : Reg.RootKey := HKEY_CURRENT_USER; LOCAL_MACHINE : Reg.RootKey := HKEY_LOCAL_MACHINE; USERS : Reg.RootKey := HKEY_USERS; PERFORMANCE_DATA : Reg.RootKey := HKEY_PERFORMANCE_DATA; CURRENT_CONFIG : Reg.RootKey := HKEY_CURRENT_CONFIG; DYN_DATA : Reg.RootKey := HKEY_DYN_DATA; end; for A := 0 to Items.Count-1 do begin S1 := Items[A]; if not IsValid(S1) then continue; {Is it read-only?} if Parse(S1,ppReadOnly,';')='1' then continue; CmpName := Parse(S1,ppComponent,';'); PrpName := Parse(S1,ppProperty,';'); Section := Parse(S1,ppSection,';'); Ident := Parse(S1,ppIdent,';'); if CmpName = TheForm.Name then TmpCmp := TheForm else {Find the component on the form} TmpCmp := TheForm.FindComponent(CmpName); {Couldn't find component - go on to next} if TmpCmp = nil then Continue; PropInfo := GetPropInfo(TmpCmp.ClassInfo,PrpName); if PropInfo = nil then Continue; try Reg.CloseKey; if Reg.OpenKey(Section,True) then Reg.WriteString(Ident,GetPropAsString(TmpCmp,PropInfo)); except end; end; finally Reg.Free; end; end; {$ENDIF} function TIniOut.ReadStringReg(const Key,Name,Default: string): string; var Reg : TRegistry; begin Reg := TRegistry.Create; try if SetupKey(Reg,Key) and Reg.ValueExists(Name) then Result := Reg.ReadString(Name) else Result := Default; finally Reg.Free; end; end; procedure TIniOut.WriteStringReg(const Key,Name,Value: string); var Reg : TRegistry; begin Reg := TRegistry.Create; try SetupKey(Reg,Key); Reg.WriteString(Name,Value); finally Reg.Free; end; end;