regini.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. {******************************************************************************
  2. TRegIniFile
  3. ******************************************************************************}
  4. constructor TRegIniFile.Create(const FN: String);
  5. begin
  6. inherited Create;
  7. fFileName := FN;
  8. if fFileName<>'' then
  9. fPath := fFileName + '\'
  10. else
  11. fPath := '';
  12. end;
  13. procedure TRegIniFile.DeleteKey(const Section, Ident: String);
  14. begin
  15. if not OpenKey(fPath+Section,true) then Exit;
  16. try
  17. DeleteValue(Ident);
  18. finally
  19. CloseKey;
  20. end;
  21. end;
  22. procedure TRegIniFile.EraseSection(const Section: string);
  23. begin
  24. inherited DeleteKey(fPath+Section);
  25. end;
  26. procedure TRegIniFile.ReadSection(const Section: string; Strings: TStrings);
  27. begin
  28. if not OpenKey(fPath+Section,false) then Exit;
  29. try
  30. GetValueNames(Strings);
  31. finally
  32. CloseKey;
  33. end;
  34. end;
  35. procedure TRegIniFile.ReadSections(Strings: TStrings);
  36. begin
  37. if not OpenKey(fFileName,false) then Exit;
  38. try
  39. GetKeyNames(Strings);
  40. finally
  41. CloseKey;
  42. end;
  43. end;
  44. procedure TRegIniFile.ReadSectionValues(const Section: string; Strings: TStrings);
  45. var
  46. ValList : TStringList;
  47. V : String;
  48. i : Integer;
  49. begin
  50. if not OpenKey(fPath+Section,false) then Exit;
  51. ValList := TStringList.Create;
  52. try
  53. GetValueNames(ValList);
  54. for i:=0 to ValList.Count-1 do
  55. begin
  56. V := inherited ReadString(ValList.Strings[i]);
  57. Strings.Add(ValList.Strings[i] + '=' + V);
  58. end;
  59. finally
  60. ValList.Free;
  61. CloseKey;
  62. end;
  63. end;
  64. procedure TRegIniFile.WriteBool(const Section, Ident: string; Value: Boolean);
  65. begin
  66. if not OpenKey(fPath+Section,true) then Exit;
  67. try
  68. inherited WriteBool(Ident,Value);
  69. finally
  70. CloseKey;
  71. end;
  72. end;
  73. procedure TRegIniFile.WriteInteger(const Section, Ident: string; Value: LongInt);
  74. begin
  75. if not OpenKey(fPath+Section,true) then Exit;
  76. try
  77. inherited WriteInteger(Ident,Value);
  78. finally
  79. CloseKey;
  80. end;
  81. end;
  82. procedure TRegIniFile.WriteString(const Section, Ident, Value: String);
  83. begin
  84. if not OpenKey(fPath+Section,true) then Exit;
  85. try
  86. inherited WriteString(Ident,Value);
  87. finally
  88. CloseKey;
  89. end;
  90. end;
  91. function TRegIniFile.ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
  92. begin
  93. Result := Default;
  94. if not OpenKey(fPath+Section,false) then Exit;
  95. try
  96. Result := inherited ReadBool(Ident);
  97. finally
  98. CloseKey;
  99. end;
  100. end;
  101. function TRegIniFile.ReadInteger(const Section, Ident: string; Default: LongInt): LongInt;
  102. begin
  103. Result := Default;
  104. if not OpenKey(fPath+Section,false) then Exit;
  105. try
  106. Result := inherited ReadInteger(Ident);
  107. finally
  108. CloseKey;
  109. end;
  110. end;
  111. function TRegIniFile.ReadString(const Section, Ident, Default: String): String;
  112. begin
  113. Result := Default;
  114. if not OpenKey(fPath+Section,false) then Exit;
  115. try
  116. Result := inherited ReadString(Ident);
  117. finally
  118. CloseKey;
  119. end;
  120. end;