AppCentreINI.pas 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. unit AppCentreINI;
  2. interface
  3. uses
  4. Classes, SysUtils, IniFiles, Forms, Windows;
  5. const
  6. csIniAppCentreSection = 'AppCentre';
  7. {Section: AppCentre}
  8. csIniAppCentreAppKey = 'AppKey';
  9. csIniAppCentreAppSecret = 'AppSecret';
  10. type
  11. TIniOptions = class(TObject)
  12. private
  13. {Section: AppCentre}
  14. FAppCentreAppKey: string;
  15. FAppCentreAppSecret: string;
  16. public
  17. procedure LoadSettings(Ini: TIniFile);
  18. procedure SaveSettings(Ini: TIniFile);
  19. procedure LoadFromFile(const FileName: string);
  20. procedure SaveToFile(const FileName: string);
  21. {Section: AppCentre}
  22. property AppCentreAppKey: string read FAppCentreAppKey write FAppCentreAppKey;
  23. property AppCentreAppSecret: string read FAppCentreAppSecret write FAppCentreAppSecret;
  24. end;
  25. var
  26. IniOptions: TIniOptions = nil;
  27. implementation
  28. procedure TIniOptions.LoadSettings(Ini: TIniFile);
  29. begin
  30. if Ini <> nil then
  31. begin
  32. {Section: AppCentre}
  33. FAppCentreAppKey := Ini.ReadString(csIniAppCentreSection, csIniAppCentreAppKey, 'ddddd');
  34. FAppCentreAppSecret := Ini.ReadString(csIniAppCentreSection, csIniAppCentreAppSecret, 'ddddd');
  35. end;
  36. end;
  37. procedure TIniOptions.SaveSettings(Ini: TIniFile);
  38. begin
  39. if Ini <> nil then
  40. begin
  41. {Section: AppCentre}
  42. Ini.WriteString(csIniAppCentreSection, csIniAppCentreAppKey, FAppCentreAppKey);
  43. end;
  44. end;
  45. procedure TIniOptions.LoadFromFile(const FileName: string);
  46. var
  47. Ini: TIniFile;
  48. begin
  49. Ini := TIniFile.Create(FileName);
  50. try
  51. LoadSettings(Ini);
  52. finally
  53. Ini.Free;
  54. end;
  55. end;
  56. procedure TIniOptions.SaveToFile(const FileName: string);
  57. var
  58. Ini: TIniFile;
  59. begin
  60. Ini := TIniFile.Create(FileName);
  61. try
  62. SaveSettings(Ini);
  63. finally
  64. Ini.Free;
  65. end;
  66. end;
  67. initialization
  68. IniOptions := TIniOptions.Create;
  69. finalization
  70. IniOptions.Free;
  71. end.