home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / apdtr.zip / ADINIDB.INT < prev    next >
Text File  |  1995-05-26  |  5KB  |  143 lines

  1. {$G+,X+,F+}
  2.  
  3. {Conditional defines that may affect this unit}
  4. {$I AWDEFINE.INC}
  5.  
  6. {*********************************************************}
  7. {*                   ADINIDB.PAS 1.00                    *}
  8. {*        Copyright (c) TurboPower Software 1995         *}
  9. {*                 All rights reserved.                  *}
  10. {*********************************************************}
  11.  
  12. unit AdIniDB;
  13.   {-Delphi INI database component}
  14.  
  15. interface
  16.  
  17. uses
  18.   {-----RTL}
  19.   SysUtils,
  20.   Classes,
  21.   Messages,
  22.   WinTypes,
  23.   DsgnIntf,
  24.   Forms,
  25.   Controls,
  26.   {-----APD}
  27.   OoMisc,
  28.   AwIniDB,
  29.   AdMisc,
  30.   AdExcept,
  31.   AdDataB,
  32.   DbFldLst;
  33.  
  34. const
  35.   DefDBName = 'DATABASE.INI';
  36.  
  37. type
  38.   {property editor for list of database fields}
  39.   TDBFieldListProperty = class(TPropertyEditor)
  40.     procedure Edit; override;
  41.     function GetAttributes : TPropertyAttributes; override;
  42.     function GetValue : String; override;
  43.   end;
  44.  
  45.   {property editor for drop-down list of indexable fields}
  46.   TIndexedFieldProperty = class(TStringProperty)
  47.     function GetAttributes : TPropertyAttributes; override;
  48.     function GetEditLimit : Integer; override;
  49.     procedure GetValues(Proc : TGetStrProc); override;
  50.     procedure SetValue(const Value : String); override;
  51.   end;
  52.  
  53.   {a database key string}
  54.   TDBKeyStr = String[MaxIndexLen];
  55.  
  56.   {INI database component}
  57.   TCustomIniDBase = class(TComponent)
  58.   private
  59.     DB            : PIniDatabase;       {record passed to DLL calls}
  60.     FRecordList   : TStringList;        {for returning record lists}
  61.     FFieldList    : TDBFieldList;       {list of database fields}
  62.     Scratch       : Pointer;            {scratch record for passing into DLL}
  63.     Changed       : Boolean;            {TRUE if database data has changed}
  64.     FOpen         : Boolean;            {TRUE if database has been opened}
  65.     FFileName     : String;             {file name, used mostly at design time}
  66.     FIndexedField : TDBIndexedField;    {name of field used for index}
  67.  
  68.     {Property read/write methods}
  69.     procedure SetFileName(const NewName : String);
  70.       {-Update the database's file name.  If open, reopen with the new name}
  71.     procedure SetOpen(const OpenIt : Boolean);
  72.       {-Open or close the database}
  73.     procedure SetFieldList(const Fields : TDBFieldList);
  74.       {-Set the database's list of fields}
  75.     procedure SetIndexedField(const S : TDBIndexedField);
  76.       {-Set the name of the field used to index the database}
  77.     function GetRecordList : TStrings;
  78.       {-Returns the key strings for each record in the database}
  79.     function GetNumRecs : Integer;
  80.       {-Returns the number of records in the database}
  81.  
  82.     {utility}
  83.     procedure AssureOpen;
  84.       {-Make sure that the database is open, otherwise raise an exception}
  85.     procedure ClearFieldList;
  86.       {-Remove all fields in the field list}
  87.     procedure DefaultIndexed;
  88.       {-Default the FIndexedField property to the first indexable field in the list}
  89.  
  90.     {streaming}
  91.     procedure ReadFields(Reader : TReader);
  92.       {-Reads the database field list from a stream}
  93.     procedure WriteFields(Writer : TWriter);
  94.       {-Writes the database field list to a stream}
  95.     procedure DefineProperties(Filer : TFiler); override;
  96.       {-Define methods for reading and writing field list}
  97.  
  98.   protected
  99.     CustComponent : Boolean;
  100.  
  101.     property FileName : String
  102.       read FFileName write SetFileName;
  103.     property FieldList : TDBFieldList
  104.       read FFieldList write SetFieldList;
  105.     property IndexedField : TDBIndexedField
  106.       read FIndexedField write SetIndexedField;
  107.  
  108.   public
  109.     {Creation/destruction}
  110.     constructor Create(AOwner : TComponent); override;
  111.     destructor Destroy; override;
  112.  
  113.     function KeyExists(const Key : TDBKeyStr) : Boolean;
  114.       {-Return TRUE if an entry with an index of 'Name' exists}
  115.     procedure AddRecord(var Rec);
  116.       {-Add a record to the database}
  117.     procedure UpdRecord(const Key : TDBKeyStr; var Rec);
  118.       {-Update a record in the database}
  119.     procedure DelRecord(const Key : TDBKeyStr);
  120.       {-Remove a record from the database}
  121.     procedure GetRecord(const Key : TDBKeyStr; var Rec);
  122.       {-Get a record from the database}
  123.     procedure WriteToIni(var Rec; const Section, IniFile : String);
  124.       {-Write the record to a user-specified .INI file}
  125.     procedure ReadFromIni(var Rec; const Section, IniFile : String);
  126.       {-Read the record from a user-specified .INI file}
  127.  
  128.     property RecordList : TStrings
  129.       read GetRecordList;
  130.     property NumRecs : Integer
  131.       read GetNumRecs;
  132.     property Open : Boolean
  133.       read FOpen write SetOpen;
  134.   end;
  135.  
  136.   TIniDBase = class(TCustomIniDBase)
  137.   published
  138.     property FileName;
  139.     property FieldList;
  140.     property IndexedField;
  141.   end;
  142.  
  143.