home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sibylft1.zip / DOC.DAT / DOC / SPCC / INIFILES.PAS < prev    next >
Pascal/Delphi Source File  |  1997-04-07  |  4KB  |  113 lines

  1.  
  2. {╔══════════════════════════════════════════════════════════════════════════╗
  3.  ║                                                                          ║
  4.  ║     Sibyl Portable Component Classes                                     ║
  5.  ║                                                                          ║
  6.  ║     Copyright (c) 1995,97 SpeedSoft Germany,   All rights reserved.      ║
  7.  ║                                                                          ║
  8.  ╚══════════════════════════════════════════════════════════════════════════╝}
  9.  
  10. unit IniFiles;
  11.  
  12. { TIniFile: Standard (binäres) OS/2 Inifile
  13.   TAsciiIniFile: Text-Inifile, lesbar, mit Editor zu bearbeiten.
  14.  
  15.   Beide benutzen exakt das gleiche Interface und sind bis
  16.   auf die neue Methode 'Erase' kompatibel zu den normalen
  17.   Delphi-Inifiles. }
  18.  
  19. interface
  20.  
  21. {Rene}
  22. uses Classes,SysUtils;
  23.  
  24. {$IFDEF OS2}
  25. USES PMSHL; { OS/2 profile functions }
  26. {$ENDIF}
  27. {$IFDEF WIN95}
  28. USES WinBase;
  29. {$ENDIF}
  30.  
  31. type
  32.   EIniFileError = class(Exception);
  33.  
  34. type
  35.   TIniFile = class(TObject)
  36.   private
  37.     FFileName: PString;         // Physical name of file
  38.     {$IFDEF OS2}
  39.     FHandle: HINI;              // Profile handle
  40.     {$ENDIF}
  41.     function GetFileName: string;
  42.  
  43.   protected
  44.     procedure Error(const Msg: string); virtual;
  45.  
  46.   public
  47.     constructor Create(const FileName: string);virtual;
  48.     destructor Destroy; override;
  49.     procedure Erase(const Section, Ident: string); virtual;
  50.     procedure EraseSection(const Section: string); virtual;
  51.     function ReadString(const Section, Ident, Default: string): string; virtual;
  52.     function ReadInteger(const Section, Ident: string; Default: Longint): Longint; virtual;
  53.     function ReadBool(const Section, Ident: string; Default: Boolean): Boolean; virtual;
  54.     procedure ReadSection(const Section: string; AStrings: TStrings); virtual;
  55.     {procedure ReadSections(AStrings: TStrings); fehlt noch}
  56.     procedure ReadSectionValues(const Section: string; AStrings: TStrings); virtual;
  57.     procedure WriteString(const Section, Ident, Value: String); virtual;
  58.     procedure WriteInteger(const Section, Ident: string; Value: Longint); virtual;
  59.     procedure WriteBool(const Section, Ident: string; Value: Boolean); virtual;
  60.  
  61.     property FileName: string
  62.       read GetFileName;
  63.   end;
  64.  
  65. type
  66.   TAsciiIniFile = class(TIniFile)
  67.   private
  68.     //FFileName: PString;         // Physical name of file
  69.     FSections: TStringList;     // List of sections and their names
  70.     FName: PString;             // Name of last used section
  71.     FList: TStringList;         // List of last used section
  72.     FChanged: Boolean;          // Has the data been changed?
  73.     procedure WriteToSection(const Section: string);
  74.     function ReadFromSection(const Section: string): Boolean;
  75.     //function GetFileName: string;
  76.  
  77.   protected
  78.     FTrueString: string[7];
  79.     FFalseString: string[7];
  80.     FSectionSort: Boolean;
  81.     FIdentSort: Boolean;
  82.   protected
  83.     procedure InitIniFile;VIRTUAL;
  84.  
  85.   public
  86.     constructor Create(const FileName: string);virtual;
  87.     destructor Destroy; override;
  88.     procedure Erase(const Section, Ident: string); override;
  89.     procedure EraseSection(const Section: string); override;
  90.     function ReadString(const Section, Ident, Default: string): string; override;
  91.     function ReadInteger(const Section, Ident: string; Default: Longint): Longint; override;
  92.     function ReadBool(const Section, Ident: string; Default: Boolean): Boolean; override;
  93.     procedure ReadSection(const Section: string; AStrings: TStrings); override;
  94.     procedure ReadSections(AStrings: TStrings);
  95.     procedure ReadSectionValues(const Section: string; AStrings: TStrings); override;
  96.     procedure Refresh;
  97.     procedure WriteString(const Section, Ident, Value: String); override;
  98.     procedure WriteInteger(const Section, Ident: string; Value: Longint); override;
  99.     procedure WriteBool(const Section, Ident: string; Value: Boolean); override;
  100.  
  101.     property FileName: string
  102.       read GetFileName;
  103.     property Changed: Boolean
  104.       read FChanged write FChanged;
  105.   end;
  106.  
  107. function GetDefaultINI: string;
  108.   { Get name of INI-file that matches program path & name with
  109.     extension .INI instead of .EXE }
  110.  
  111. implementation
  112.  
  113.