ApplicationConfiguration.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 23210: ApplicationConfiguration.pas
  11. {
  12. { Rev 1.0 09/11/2003 3:19:50 PM Jeremy Darling
  13. { Added to project for a place to store application configuration information.
  14. }
  15. unit ApplicationConfiguration;
  16. interface
  17. uses
  18. Graphics,
  19. IniFiles,
  20. SysUtils,
  21. Classes;
  22. type
  23. TLogColors=class(TStringList)
  24. private
  25. function GetColors(shortname: string): TColor;
  26. procedure SetColors(shortname: string; const Value: TColor);
  27. public
  28. property Colors[shortname:string]:TColor read GetColors write SetColors;
  29. end;
  30. TApplicationConfig = class
  31. private
  32. FLogColors: TLogColors;
  33. public
  34. property LogColors : TLogColors read FLogColors;
  35. procedure LoadFromIni(Ini : TIniFile);
  36. procedure SaveToIni(Ini : TIniFile);
  37. constructor Create;
  38. destructor Destroy; override;
  39. end;
  40. implementation
  41. { TApplicationConfig }
  42. constructor TApplicationConfig.Create;
  43. begin
  44. inherited;
  45. FLogColors := TLogColors.Create;
  46. end;
  47. destructor TApplicationConfig.Destroy;
  48. begin
  49. FLogColors.Free;
  50. inherited;
  51. end;
  52. procedure TApplicationConfig.LoadFromIni(Ini: TIniFile);
  53. var
  54. i,
  55. v : Integer;
  56. n : String;
  57. sl: TStringList;
  58. begin
  59. sl := TStringList.Create;
  60. try
  61. Ini.ReadSection('LOGCOLORS', sl);
  62. for i := 0 to sl.Count -1 do
  63. begin
  64. n := sl[i];
  65. v := Ini.ReadInteger('LOGCOLORS', n, Integer(LogColors.Colors[n]));
  66. LogColors[i] := n;
  67. LogColors.Colors[n] := TColor(v);
  68. end;
  69. finally
  70. sl.Free;
  71. end;
  72. end;
  73. procedure TApplicationConfig.SaveToIni(Ini: TIniFile);
  74. var
  75. i : Integer;
  76. begin
  77. for i := 0 to LogColors.Count -1 do
  78. begin
  79. Ini.WriteInteger('LOGCOLORS', LogColors[i], Integer(LogColors.Colors[LogColors[i]]));
  80. end;
  81. end;
  82. { TLogColors }
  83. function TLogColors.GetColors(shortname: string): TColor;
  84. begin
  85. if indexof(shortname) > -1 then
  86. result := TColor(Pointer(Objects[indexof(shortname)]))
  87. else
  88. result := clBlack;
  89. end;
  90. procedure TLogColors.SetColors(shortname: string; const Value: TColor);
  91. begin
  92. if indexof(shortname) = -1 then
  93. AddObject(shortname, pointer(value))
  94. else
  95. Objects[indexof(shortname)] := pointer(value);
  96. end;
  97. end.