home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri K-CD 2002 #1 / K-CD_2002-01.iso / Delphi / INSTALL / program files / Borland / Delphi6 / Doc / IniFiles.int < prev    next >
Encoding:
Text File  |  2001-05-22  |  5.7 KB  |  131 lines

  1. { *************************************************************************** }
  2. {                                                                             }
  3. { Delphi and Kylix Cross-Platform Visual Component Library                    }
  4. {                                                                             }
  5. { Copyright (c) 1995, 2001 Borland Software Corporation                       }
  6. {                                                                             }
  7. { *************************************************************************** }
  8.  
  9.  
  10. unit IniFiles;
  11.  
  12. {$R-,T-,H+,X+}
  13.  
  14. interface
  15.  
  16. uses SysUtils, Classes;
  17.  
  18. type
  19.   EIniFileException = class(Exception);
  20.  
  21.   TCustomIniFile = class(TObject)
  22.   public
  23.     constructor Create(const FileName: string);
  24.     function SectionExists(const Section: string): Boolean;
  25.     function ReadString(const Section, Ident, Default: string): string; virtual; abstract;
  26.     procedure WriteString(const Section, Ident, Value: String); virtual; abstract;
  27.     function ReadInteger(const Section, Ident: string; Default: Longint): Longint; virtual;
  28.     procedure WriteInteger(const Section, Ident: string; Value: Longint); virtual;
  29.     function ReadBool(const Section, Ident: string; Default: Boolean): Boolean; virtual;
  30.     procedure WriteBool(const Section, Ident: string; Value: Boolean); virtual;
  31.     function ReadBinaryStream(const Section, Name: string; Value: TStream): Integer; virtual;
  32.     function ReadDate(const Section, Name: string; Default: TDateTime): TDateTime; virtual;
  33.     function ReadDateTime(const Section, Name: string; Default: TDateTime): TDateTime; virtual;
  34.     function ReadFloat(const Section, Name: string; Default: Double): Double; virtual;
  35.     function ReadTime(const Section, Name: string; Default: TDateTime): TDateTime; virtual;
  36.     procedure WriteBinaryStream(const Section, Name: string; Value: TStream); virtual;
  37.     procedure WriteDate(const Section, Name: string; Value: TDateTime); virtual;
  38.     procedure WriteDateTime(const Section, Name: string; Value: TDateTime); virtual;
  39.     procedure WriteFloat(const Section, Name: string; Value: Double); virtual;
  40.     procedure WriteTime(const Section, Name: string; Value: TDateTime); virtual;
  41.     procedure ReadSection(const Section: string; Strings: TStrings); virtual; abstract;
  42.     procedure ReadSections(Strings: TStrings); virtual; abstract;
  43.     procedure ReadSectionValues(const Section: string; Strings: TStrings); virtual; abstract;
  44.     procedure EraseSection(const Section: string); virtual; abstract;
  45.     procedure DeleteKey(const Section, Ident: String); virtual; abstract;
  46.     procedure UpdateFile; virtual; abstract;
  47.     function ValueExists(const Section, Ident: string): Boolean;
  48.     property FileName: string;
  49.   end;
  50.  
  51.   { TStringHash - used internally by TMemIniFile to optimize searches. }
  52.  
  53.   PPHashItem = ^PHashItem;
  54.   PHashItem = ^THashItem;
  55.   THashItem = record
  56.     Next: PHashItem;
  57.     Key: string;
  58.     Value: Integer;
  59.   end;
  60.  
  61.   TStringHash = class
  62.   protected
  63.     function Find(const Key: string): PPHashItem;
  64.     function HashOf(const Key: string): Cardinal; virtual;
  65.   public
  66.     constructor Create(Size: Integer = 256);
  67.     destructor Destroy; override;
  68.     procedure Add(const Key: string; Value: Integer);
  69.     procedure Clear;
  70.     procedure Remove(const Key: string);
  71.     function Modify(const Key: string; Value: Integer): Boolean;
  72.     function ValueOf(const Key: string): Integer;
  73.   end;
  74.  
  75.   { THashedStringList - A TStringList that uses TStringHash to improve the
  76.     speed of Find }
  77.   THashedStringList = class(TStringList)
  78.   protected
  79.     procedure Changed; override;
  80.   public
  81.     destructor Destroy; override;
  82.     function IndexOf(const S: string): Integer; override;
  83.     function IndexOfName(const Name: string): Integer; override;
  84.   end;
  85.  
  86.   { TMemIniFile - loads and entire ini file into memory and allows all
  87.     operations to be performed on the memory image.  The image can then
  88.     be written out to the disk file }
  89.  
  90.   TMemIniFile = class(TCustomIniFile)
  91.   public
  92.     constructor Create(const FileName: string);
  93.     destructor Destroy; override;
  94.     procedure Clear;
  95.     procedure DeleteKey(const Section, Ident: String); override;
  96.     procedure EraseSection(const Section: string); override;
  97.     procedure GetStrings(List: TStrings);
  98.     procedure ReadSection(const Section: string; Strings: TStrings); override;
  99.     procedure ReadSections(Strings: TStrings); override;
  100.     procedure ReadSectionValues(const Section: string; Strings: TStrings); override;
  101.     function ReadString(const Section, Ident, Default: string): string; override;
  102.     procedure Rename(const FileName: string; Reload: Boolean);
  103.     procedure SetStrings(List: TStrings);
  104.     procedure UpdateFile; override;
  105.     procedure WriteString(const Section, Ident, Value: String); override;
  106.     property CaseSensitive: Boolean;
  107.   end;
  108.  
  109. {$IFDEF MSWINDOWS}
  110.   { TIniFile - Encapsulates the Windows INI file interface
  111.     (Get/SetPrivateProfileXXX functions) }
  112.  
  113.   TIniFile = class(TCustomIniFile)
  114.   public
  115.     destructor Destroy; override;
  116.     function ReadString(const Section, Ident, Default: string): string; override;
  117.     procedure WriteString(const Section, Ident, Value: String); override;
  118.     procedure ReadSection(const Section: string; Strings: TStrings); override;
  119.     procedure ReadSections(Strings: TStrings); override;
  120.     procedure ReadSectionValues(const Section: string; Strings: TStrings); override;
  121.     procedure EraseSection(const Section: string); override;
  122.     procedure DeleteKey(const Section, Ident: String); override;
  123.     procedure UpdateFile; override;
  124.   end;
  125. {$ELSE}
  126.     TIniFile = class(TMemIniFile);
  127. {$ENDIF}
  128.  
  129.  
  130. implementation
  131.