RegFiles.pas
上传用户:mjqmds
上传日期:2022-05-05
资源大小:2827k
文件大小:24k
- Unit RegFiles;
- Interface
- Uses
- Windows,
- SysUtils,
- Dialogs,
- Classes,
- Registry,
- ShellAPI,
- ShlObj;
- Procedure UpdateAssociationToSystem;
- //Check AssociationPath and update Path
- Procedure UpdateAssociationPath(Const KeyName, FileName: String);
- //Set a value in the registry;
- Procedure SetValInReg(RKey: HKey; KeyPath: String; ValName: String; NewVal: String);
- Procedure RegisterAllFileType(MenuName, Command: String);
- {Click on a File in Explorer with right mouse key ,
- uses this function you may add new menu item to popup menu
- MenuName:display on the popup menu name
- Command: execute command
- eg:
- RegisterAllFileType(sFileMenuName, '"' + Application.ExeName + '" "%1"');
- }
- Procedure UnRegisterAllFileType(MenuName: String);
- Function ExtDescription(Ext: String): String;
- {if ExtDescription(File type description) then return such description}
- Function AssociationExists(Ext: String; Var FileName: String): String;
- { Ext: Extension Name (eg: ".txt")
- if no AssociationExists then return ''
- else return Association Key Name and Execute File Name
- }
- Function DoesKeyExist(AKey: String): Boolean;
- Function DeleteAssociation(RegKey, Ext: String): Boolean;
- { Desc: if old association exists then fisrt restore old one , then delete.
- }
- Function ClearAssociation(RegKey, Ext: String): Boolean;
- { Desc: if old association exists then fisrt restore old one , then clear.
- }
- //Clears or Removes an Association with or without updating desktop
- Function RemoveAssociation(RegKey, Ext: String; RemoveKeyName: Boolean; UpdateSystem: Boolean): Boolean;
- { Desc: if old association exists then fisrt restore old one , then Remove.
- }
- Procedure CreateAssociation(Ext: String; FileName: String;
- DefaultIcon: String; KeyName: String;
- FileType: String; ShowInNew: Boolean);
- { Params Description:
- Ext: Extension Name
- FileName: Execute File Name include path(eg "d:appsxxx.exe")
- DefaultIcon: eg, use the first icon in execute file: "D:APPSxxxx.exe,0"
- KeyName: Ext Key Name, such as "JediEdit.c"
- FileType: File Type Description, such as 'C Language File'
- ShowInNew: if true then put command(Execute File Name) into 'ShellNew' register Key
- else put into 'Shell' register key
- Desc: first try to backup old Association then CreateAssociation.
- }
- //Makes association
- Procedure MakeAssociation(Ext: String; PgmToLinkTo: String;
- DefaultIcon: String; KeyName: String;
- TypeName: String; ShowInNew: Boolean);
- { Ext: Extension Name
- pgmToLinkTo: Execute File Name include path(eg "d:appsxxx.exe")
- KeyName:
- Desc: see above, this function no error check.
- }
- {------------Low Level Functions---------}
- Function RemoveParams(Value: String): String;
- Function SaveIntToRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: Integer): Boolean;
- Function LoadIntFromRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: Integer): Integer;
- Function SaveStrToRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: String): Boolean;
- Function LoadStrFromRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: String): String;
- Function SaveBoolToRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: Boolean): Boolean;
- Function LoadBoolFromRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: Boolean): Boolean;
- {Deletes a key with and subkeys on win95}
- Function DeleteRegKey(MainKey: LongInt; AKey: String): Boolean;
- {Deletes a key with and subkeys on win95/NT}
- Function NTDeleteRegKey(MainKey: LongInt; Const AKey: String): Boolean;
- {Sets a stringlist with all subkeys}
- Function GetRegSubTree(MainKey: LongInt; AKey, AValue: String; Const AList: TStrings): Boolean;
- { if aValue <> '' then these subkeys must include aValue string.
- }
- {The following methods return or set the default key values}
- Procedure ChangeRegistryInt(mainKey: LongInt; AKey: String; AValue: LongInt);
- Procedure ChangeRegistryStr(mainKey: LongInt; AKey: String; AValue: String);
- Procedure ChangeRegistryBool(mainKey: LongInt; AKey: String; AValue: Boolean);
- Function GetRegistryStr(mainKey: LongInt; AKey: String; Default: String): String;
- Function GetRegistryInt(mainKey: LongInt; AKey: String; Default: Integer): Integer;
- Function GetRegistryBool(MainKey: LongInt; AKey: String; Default: Boolean): Boolean;
- Const
- sOldDefault = 'Old Default';
- Implementation
- //Set a value in the registry;
- Procedure SetValInReg(RKey: HKey; KeyPath: String;
- ValName: String; NewVal: String);
- Begin
- With TRegistry.Create Do Try
- RootKey := RKey;
- OpenKey(KeyPath, True);
- WriteString(ValName, NewVal);
- Finally
- Free;
- End;
- End;
- Procedure RegisterAllFileType(MenuName, Command: String);
- {Click on a File in Explorer with right mouse key ,
- uses this function you may add new menu item to popup menu
- MenuName:display on the popup menu name
- Command: execute command}
- Begin
- SetValInReg(HKEY_CLASSES_ROOT, '*shell' + MenuName + 'command', '', Command);
- // SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_FLUSH,pchar(''),pchar('')); {update system of assocciation change}
- End;
- Procedure UnRegisterAllFileType(MenuName: String);
- Begin
- NTDeleteRegKey(LongInt(HKEY_CLASSES_ROOT), '*Shell' + MenuName);
- // SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_FLUSH,pchar(''),pchar('')); {update system of assocciation change}
- End;
- Function ExtDescription(Ext: String): String;
- Var
- AReg: TRegistry;
- AssocKey: String;
- Begin
- Result := ''; {initialize result to empty string if exception occurrs}
- AReg := TRegistry.Create;
- Try
- AReg.RootKey := HKEY_CLASSES_ROOT;
- //Lowercase to avoid trouble
- Ext := LowerCase(Ext);
- If AReg.KeyExists(Ext) Then Begin
- AReg.OpenKey(Ext, False);
- AssocKey := AReg.ReadString('');
- AReg.CloseKey;
- If AReg.OpenKey(AssocKey, False) Then Begin
- Result := AReg.ReadString('');
- Exit;
- End;
- End;
- Finally
- AReg.Free;
- End; //try
- End;
- Procedure UpdateAssociationPath(Const KeyName, FileName: String);
- Var
- AReg: TRegistry;
- s: String;
- Begin
- AReg := TRegistry.Create;
- Try
- AReg.RootKey := HKEY_CLASSES_ROOT;
- If AReg.OpenKey(KeyName, False) Then Begin
- If AReg.OpenKey('ShellOpenCommand', False) Then Begin
- s := RemoveParams(AReg.ReadString(''));
- If UpperCase(s) <> UpperCase(FileName) Then
- AReg.WriteString('', '"' + FileName + '" "%1"');
- End;
- End;
- Finally
- AReg.Free;
- End; //try
- End;
- Function AssociationExists(Ext: String; Var FileName: String): String;
- Var
- AReg: TRegistry;
- AssocKey: String;
- Begin
- Result := ''; {initialize result to empty string if exception occurrs}
- FileName := '';
- AReg := TRegistry.Create;
- Try
- AReg.RootKey := HKEY_CLASSES_ROOT;
- //Lowercase to avoid trouble
- Ext := LowerCase(Ext);
- //Check if the key (.???) exists
- // If Pos('.', Ext)=0 then Ext:='.'+Ext;
- If Not AReg.KeyExists(Ext) Then Begin
- Result := '';
- End
- Else Begin
- AReg.OpenKey(Ext, False);
- AssocKey := AReg.ReadString('');
- Result := AssocKey;
- AReg.CloseKey;
- If Not AReg.OpenKey(AssocKey, False) Then Begin
- Result := '';
- Exit;
- End;
- If Not AReg.OpenKey('ShellOpenCommand', False) Then Begin
- Result := AReg.ReadString('');
- Exit;
- End;
- FileName := RemoveParams(AReg.ReadString(''));
- End;
- Finally
- AReg.Free;
- End; //try
- End;
- //Clears or Removes an Association with or without updating desktop
- Function RemoveAssociation(RegKey, Ext: String; RemoveKeyName: Boolean; UpdateSystem: Boolean): Boolean;
- Begin
- If RemoveKeyName Then
- Result := DeleteAssociation(RegKey, Ext)
- Else
- Result := ClearAssociation(RegKey, Ext);
- If UpdateSystem Then
- SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, PChar(''), PChar('')); {update system of assocciation change}
- End;
- Function ClearAssociation(RegKey, Ext: String): Boolean;
- Var
- OldKeyName: String;
- Begin
- Result := False;
- If Ext = '' Then Exit; {only perform if valid}
- // If Pos('.', Ext)=0 then Ext:='.'+FExt;
- If DoesKeyExist(RegKey) Then Begin
- OldKeyName := LoadStrFromRegistry(LongInt(HKEY_CLASSES_ROOT), RegKey, //register key
- sOldDefault, //specify the data item
- ''); //default return Value
- SetValInReg(HKEY_CLASSES_ROOT,
- Ext, { extension we want to define }
- '', { specify the default data item }
- OldKeyName); { clear or restore reference to association }
- End;
- End;
- Function DeleteAssociation(RegKey, Ext: String): Boolean;
- Var
- OldKeyName: String;
- Begin
- Result := False; {initialize result}
- If Ext = '' Then Exit; {only perform if not empty}
- // If Pos('.', Ext)=0 then Ext:='.'+Ext; {make sure its a extension}
- Ext := LowerCase(Ext);
- If Not DoesKeyExist(Ext) Then Exit; {only perform if registered file extension}
- OldKeyName := GetRegistryStr(LongInt(HKEY_CLASSES_ROOT), Ext, ''); {Get the registered file extension' regKey}
- If OldKeyName <> RegKey Then Exit; {only perform if OldKeyName matches the regKey}
- OldKeyName := LoadStrFromRegistry(LongInt(HKEY_CLASSES_ROOT),
- RegKey, //register key
- sOldDefault, //specify the data item
- ''); //default return Value
- Result := NTDeleteRegKey(LongInt(HKEY_CLASSES_ROOT), Ext); {remove keys and subkeys for extension}
- If Not Result Then Exit; {error occurred get out}
- Result := NTDeleteRegKey(LongInt(HKEY_CLASSES_ROOT), RegKey); {remove keys and subkeys for association}
- If OldKeyName <> '' Then {Restore Old Default association} Begin
- SetValInReg(HKEY_CLASSES_ROOT,
- Ext, { extension we want to define }
- '', { specify the default data item }
- OldKeyName); { restore reference to association }
- End;
- End;
- Function DoesKeyExist(AKey: String): Boolean;
- Var
- AReg: TRegistry;
- Begin
- AReg := TRegistry.Create;
- Try
- AReg.RootKey := HKEY_CLASSES_ROOT;
- Result := AReg.OpenKey(AKey, False);
- Finally
- AReg.Free;
- End;
- End;
- Procedure UpdateAssociationToSystem;
- Begin
- SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, PChar(''), PChar('')); {update system of assocciation change}
- End;
- Procedure CreateAssociation(Ext: String; FileName: String;
- DefaultIcon: String; KeyName: String;
- FileType: String; ShowInNew: Boolean);
- Begin
- if Not ShowInNew then
- begin
- If (Ext = '') Or (KeyName = '') Then Exit;
- // If Pos('.', Ext)=0 then Ext:='.'+Ext;
- MakeAssociation(Ext, FileName, DefaultIcon, KeyName, FileType, ShowInNew);
- end;
- if ShowInNew then
- SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, PChar(''), PChar('')); {update system of assocciation change}
- End;
- //Makes association
- Procedure MakeAssociation(Ext: String; PgmToLinkTo: String;
- DefaultIcon: String; KeyName: String;
- TypeName: String; ShowInNew: Boolean);
- Var
- oldKeyName: String;
- Begin
- { ALL extensions must be in lowercase to avoid trouble! }
- Ext := LowerCase(Ext);
- If FileExists(PgmToLinkTo) Then Begin
- OldKeyName := LoadStrFromRegistry(LongInt(HKEY_CLASSES_ROOT),
- Ext, //register key
- '', //specify the default data item
- ''); //default return Value
- SetValInReg(HKEY_CLASSES_ROOT,
- Ext, { extension we want to define }
- '', { specify the default data item }
- KeyName); { This is the value of the default data item -
- this referances our new type to be defined }
- If ShowInNew Then Begin
- SetValInReg(HKEY_CLASSES_ROOT,
- Ext + 'ShellNew', // you forgot to add the shellnew Almer
- 'Nullfile',
- '');
- SetValInReg(HKEY_CLASSES_ROOT,
- KeyName + 'ShellNew', // you forgot to set the key shellnew Also
- '',
- 'Nullfile');
- End;
- SetValInReg(HKEY_CLASSES_ROOT,
- KeyName, { this is the type we want to define }
- '', { specify the default data item }
- TypeName); { This is the value of the default data item -
- this is the English description of the file type }
- //lxy 2001-9-11 SetValInReg(HKEY_CLASSES_ROOT,
- //lxy 2001-9-11 KeyName + 'shellopencommand', { create a file...open key }
- //lxy 2001-9-11 '', { specify the default data item }
- //lxy 2001-9-11 '"' + PgmToLinkTo + '" "%1"'); { command line to open file with }
- SetValInReg(HKEY_CLASSES_ROOT, //lxy 2001-9-11
- KeyName + 'shellopencommand', { create a file...open key }//lxy 2001-9-11
- '', { specify the default data item } //lxy 2001-9-11
- PgmToLinkTo + ' "%1"'); { command line to open file with } //lxy 2001-9-11
- SetValInReg(HKEY_CLASSES_ROOT, //lxy 2001-9-11
- KeyName + 'DefaultIcon', //lxy 2001-9-11
- '', { specify the default data item } //lxy 2001-9-11
- PgmToLinkTo + ',0'); //lxy 2001-9-11
- If DefaultIcon <> '' Then
- SetValInReg(HKEY_CLASSES_ROOT,
- KeyName + 'DefaultIcon', '', DefaultIcon);
- If OldKeyName <> '' Then
- SetValInReg(HKEY_CLASSES_ROOT,
- KeyName, sOldDefault, OldKeyName);
- End {of MakeAssociation}
- Else
- // ShowMessage('Error: Program not found: ' + PgmToLinkTo);
- // MessageDlg('Error: Program not found: ' + PgmToLinkTo, mtInformation,[mbOk], 0);
- MessageBox(0,PChar('Error: Program not found: ' + PgmToLinkTo),'提示信息',MB_ICONERROR + MB_OK);
- End;
- {------------Low Level Functions---------}
- Function RemoveParams(Value: String): String;
- Var
- i: Integer;
- Begin
- Value := UpperCase(Value);
- i := Pos('.EXE', Value);
- If ((i < (Length(Value) - 4)) And (i > 0)) Then
- Result := Copy(Value, 1, i + 3)
- Else
- Result := Value;
- If Result[1] = '"' Then Delete(Result, 1, 1);
- End;
- // Writen by Dale (stryder) Clarke
- // This function sets the default value of the key to a string.
- Procedure ChangeRegistryStr(mainKey: LongInt; AKey: String; AValue: String);
- Var
- szKey, SzValue: PChar;
- Begin
- szKey := StrAlloc(Length(AKey) + 1);
- SzValue := StrAlloc(Length(AValue) + 1);
- StrPCopy(szKey, AKey);
- StrPCopy(SzValue, AValue);
- RegSetValue(MainKey, szKey, REG_SZ, SzValue, StrLen(SzValue));
- StrDispose(szKey);
- StrDispose(SzValue);
- End;
- // Writen by Dale (stryder) Clarke
- // This function sets the default value of the key to a boolean.
- Procedure ChangeRegistryBool(mainKey: LongInt; AKey: String; AValue: Boolean);
- Var
- szKey, SzValue: PChar;
- BoolStr: String;
- Begin
- If AValue = True Then
- BoolStr := 'TRUE'
- Else
- BoolStr := 'FALSE';
- szKey := StrAlloc(Length(AKey) + 1);
- SzValue := StrAlloc(Length(BoolStr) + 1);
- StrPCopy(szKey, AKey);
- StrPCopy(SzValue, BoolStr);
- RegSetValue(MainKey, szKey, REG_SZ, SzValue, StrLen(SzValue));
- StrDispose(szKey);
- StrDispose(SzValue);
- End;
- // Writen by Dale (stryder) Clarke
- // This function sets the default value of the key to a integer.
- Procedure ChangeRegistryInt(mainKey: LongInt; AKey: String; AValue: LongInt);
- Var
- szKey, SzValue: PChar;
- IntegerStr: String;
- Begin
- IntegerStr := IntToStr(AValue);
- szKey := StrAlloc(Length(AKey) + 1);
- SzValue := StrAlloc(Length(IntegerStr) + 1);
- StrPCopy(szKey, AKey);
- StrPCopy(SzValue, IntegerStr);
- RegSetValue(MainKey, szKey, REG_SZ, SzValue, StrLen(SzValue));
- StrDispose(szKey);
- StrDispose(SzValue);
- End;
- // Writen by Dale (stryder) Clarke
- // This function returns a string value for the given key if the key does not exist
- // the key will be created with the default value.
- Function GetRegistryStr(MainKey: LongInt; AKey: String; Default: String): String;
- Var
- szKey, SzValue: PChar;
- nRet, NSize: LongInt;
- Begin
- szKey := StrAlloc(Length(AKey) + 1);
- SzValue := StrAlloc(1000);
- StrPCopy(szKey, AKey);
- StrPCopy(SzValue, '');
- NSize := 1000;
- nRet := RegQueryValue(MainKey, szKey, SzValue, NSize);
- If (nRet = ERROR_SUCCESS) Then
- Result := StrPas(SzValue)
- Else
- Result := Default;
- StrDispose(szKey);
- StrDispose(SzValue);
- End;
- // Writen by Dale (stryder) Clarke
- // This function returns a boolean value for the given key if the key does not exist
- // the key will be created with the default value.
- Function GetRegistryBool(MainKey: LongInt; AKey: String; Default: Boolean): Boolean;
- Var
- BoolStr: String;
- szKey, SzValue: PChar;
- nRet, NSize: LongInt;
- Begin
- If Default = True Then
- BoolStr := 'TRUE'
- Else
- BoolStr := 'FALSE';
- szKey := StrAlloc(Length(AKey) + 1);
- SzValue := StrAlloc(1000);
- StrPCopy(szKey, AKey);
- StrPCopy(SzValue, BoolStr);
- NSize := 1000;
- nRet := RegQueryValue(MainKey, szKey, SzValue, NSize);
- If (nRet = ERROR_SUCCESS) Then Begin
- BoolStr := StrPas(SzValue);
- If BoolStr = 'TRUE' Then
- Result := True
- Else
- Result := False;
- End
- Else
- Result := Default;
- StrDispose(szKey);
- StrDispose(SzValue);
- End;
- // Writen by Dale (stryder) Clarke
- // This function returns a integer value for the given key if the key does not exist
- // the key will be created with the default value.
- Function GetRegistryInt(MainKey: LongInt; AKey: String; Default: Integer): Integer;
- Var
- szKey, SzValue: PChar;
- AString: String;
- nRet, NSize: LongInt;
- Begin
- szKey := StrAlloc(Length(AKey) + 1);
- SzValue := StrAlloc(32);
- StrPCopy(szKey, AKey);
- NSize := 32;
- nRet := RegQueryValue(MainKey, szKey, SzValue, NSize);
- AString := StrPas(SzValue);
- StrDispose(szKey);
- StrDispose(SzValue);
- If (nRet = ERROR_SUCCESS) Then
- GetRegistryInt := StrToInt(AString)
- Else
- GetRegistryInt := Default;
- End;
- // Writen by Dale (stryder) Clarke
- // This function returns a stringlist of names of a valid
- // registration key. You can yous this to recursivly look for
- // more subkeys. Remember to always pass a initialized stringlist
- // and to free it yourself.
- Function GetRegSubTree(MainKey: LongInt; AKey, AValue: String;
- Const AList: TStrings): Boolean;
- Var
- hRoot: HKey;
- lItem: LongInt;
- hError: LongInt;
- szKey, Pdata: PChar;
- // aString : String;
- Begin
- GetRegSubTree := False;
- If AList = Nil Then Exit;
- {create pointers for the API}
- szKey := StrAlloc(Length(AKey) + 1);
- try
- StrPCopy(szKey, AKey);
- lItem := 0;
- Pdata := StrAlloc(1024);
- try
- hError := RegOpenKey(MainKey, szKey, hRoot);
- If hError = ERROR_SUCCESS Then Begin
- While (hError = ERROR_SUCCESS) Do Begin
- hError := RegEnumKey(hRoot, lItem, Pdata, 1024);
- If (hError = ERROR_SUCCESS) Then Begin
- GetRegSubTree := True;
- Inc(lItem);
- If (AValue <> '') And (AnsiPos(UpperCase(AValue), UpperCase(Pdata)) = 0) Then
- Continue; //no match, skip, don't add to list.
- AList.Add(StrPas(Pdata));
- End;
- End;
- RegCloseKey(hRoot);
- End;
- finally
- StrDispose(Pdata);
- end;
- finally
- StrDispose(szKey);
- end;
- End;
- // Writen by Dale (stryder) Clarke
- // On Win 95 this removes all subkeys but on NT the key is
- // only removed if it has NO subkeys. So always call NTDeleteRegKey
- // so if this fails it will recursively remove the keys.
- Function DeleteRegKey(MainKey: LongInt; AKey: String): Boolean;
- Var
- szKey: PChar;
- Begin
- {RegDeletKey API wants a pointer}
- szKey := StrAlloc(Length(AKey) + 1);
- StrPCopy(szKey, AKey);
- // Let windows remove the subkey's safely by bypassing VCL
- // This call is exported in the winreg unit to a call to the ADVAPI.DLL
- // I have never encounter a exception here but better safe than sorry.
- // Mickey may change the API (as if they've done that before)
- Try
- Result := (RegDeleteKey(MainKey, szKey) = ERROR_SUCCESS);
- Finally
- StrDispose(szKey); {make sure pointer is free when exit}
- End;
- End;
- // Writen by Dale (stryder) Clarke
- // This function is extreemly dangerous. The key specified and all subkeys WILL be removed.
- // Especially DO NOT pass the string SOFTWARE or anyother important registry root folder.
- // On NT RegDeleteKey will not remove a key if it has subkeys.
- // This function will remove all sukeys on NT
- Function NTDeleteRegKey(MainKey: LongInt; Const AKey: String): Boolean;
- Var
- AList: TStringList;
- s: String;
- i: Integer;
- Begin
- AList := TStringList.Create;
- Result := False;
- Try
- s := AKey;
- If GetRegSubTree(MainKey, AKey, '', AList) Then {check for subkeys} Begin
- For i := 0 To AList.Count - 1 Do Begin
- NTDeleteRegKey(MainKey, s + '' + AList[i]); {recurse to look for more subkeys}
- Result := DeleteRegKey(MainKey, s); {no subkeys so delete}
- End;
- End Else Result := DeleteRegKey(MainKey, s); {no subkeys so delete}
- Finally
- AList.Free;
- End;
- End;
- // Writen by Dale (stryder) Clarke
- // This function saves a string to a registry key.
- Function SaveIntToRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: Integer): Boolean;
- Var
- RegVar: TRegistry;
- Begin
- Result := False;
- RegVar := TRegistry.Create;
- RegVar.RootKey := MainKey;
- Try
- If RegVar.OpenKey(RegistryKey, True) Then Begin
- RegVar.WriteInteger(AItem, AValue);
- Result := True;
- End;
- Finally
- RegVar.Free;
- End;
- End;
- // Writen by Dale (stryder) Clarke
- // This function returns a integer from a registry key.
- Function LoadIntFromRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: Integer): Integer;
- Var
- RegVar: TRegistry;
- Begin
- Result := AValue;
- RegVar := TRegistry.Create;
- RegVar.RootKey := MainKey;
- Try
- If RegVar.OpenKey(RegistryKey, True) Then Begin
- If RegVar.ValueExists(AItem) Then Begin
- Result := RegVar.ReadInteger(AItem);
- End;
- End;
- Finally
- RegVar.Free;
- End;
- End;
- // Writen by Dale (stryder) Clarke
- // This function saves a string to a registry key.
- Function SaveStrToRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: String): Boolean;
- Var
- RegVar: TRegistry;
- Begin
- Result := False;
- RegVar := TRegistry.Create;
- RegVar.RootKey := MainKey;
- Try
- If RegVar.OpenKey(RegistryKey, True) Then Begin
- RegVar.WriteString(AItem, AValue);
- Result := True;
- End;
- Finally
- RegVar.Free;
- End;
- End;
- // Writen by Dale (stryder) Clarke
- // This function returs a string from a registry key.
- Function LoadStrFromRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: String): String;
- Var
- RegVar: TRegistry;
- Begin
- Result := AValue;
- RegVar := TRegistry.Create;
- RegVar.RootKey := MainKey;
- Try
- If RegVar.OpenKey(RegistryKey, True) Then Begin
- If RegVar.ValueExists(AItem) Then Begin
- Result := RegVar.ReadString(AItem);
- End;
- End;
- Finally
- RegVar.Free;
- End;
- End;
- // Writen by Dale (stryder) Clarke
- // This function saves a boolean to a registry key.
- Function SaveBoolToRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: Boolean): Boolean;
- Var
- RegVar: TRegistry;
- Begin
- Result := False;
- RegVar := TRegistry.Create;
- RegVar.RootKey := MainKey;
- Try
- If RegVar.OpenKey(RegistryKey, True) Then Begin
- RegVar.WriteBool(AItem, AValue);
- Result := True;
- End;
- Finally
- RegVar.Free;
- End;
- End;
- // Writen by Dale (stryder) Clarke
- // This function returns a boolean from a registry key.
- Function LoadBoolFromRegistry(MainKey: LongInt; RegistryKey, AItem: String; AValue: Boolean): Boolean;
- Var
- RegVar: TRegistry;
- Begin
- Result := AValue;
- RegVar := TRegistry.Create;
- RegVar.RootKey := MainKey;
- Try
- If RegVar.OpenKey(RegistryKey, True) Then Begin
- If RegVar.ValueExists(AItem) Then Begin
- Result := RegVar.ReadBool(AItem);
- End;
- End;
- Finally
- RegVar.Free;
- End;
- End;
- Initialization
- Finalization
- End.