unit OoTable; {Object Oriented Table. At least I think so..} { Author: Michael Ax Copyright (c) 1995 Michael Ax. All Rights Reserved. This source code may be used and modified by anyone with a license to WebHub or TPack from HREF Tools Corp. Obtain purchasing and additional information by sending an email to to software@href.com (any subject, any message)... or visit us on the web at http://www.href.com/software/ Send eMail to code@href.com for technical support. } {we're going to create a property that represents the current record's unique id } interface uses db, dbtables; type TTableUniqueIDField=class(TTable) private fUniqueID: TField; {making this a pointer to the tField rather than an index keeps things simple and fast} protected function GetUniqueID:LongInt; procedure SetUniqueID(aValue:LongInt); public procedure DoAfterOpen; Override; published property UniqueID: LongInt read GetUniqueID write SetUniqueID stored false; end; {modified but not tested as published in this sample} {note: while you could make this a component you probably'd want to define individual components for every major table in the system vis inheritance.. but that get tricky if you want tables to know about each other. otoh you can create new instance of tables easy if they have a type. you can set table names in the Create procs so that you can instantiate and open them without knowing a tablename or alias!..} TCustomerTable= class(TTableUniqueIDField); {that's enough to get an alias type for this} const cUniqueID='UniqueID'; {reference to the field name. use a stringtable resource!} implementation procedure TTableUniqueIDField.DoAfterOpen; begin inherited DoAfterOpen; fUniqueID:=FieldByName(cUniqueId); {raises exception if not there} fUniqueID.ReadOnly:=True; {user can not change the field} end; procedure TTableUniqueIDField.SetUniqueID(aValue:LongInt); begin if State<>dsInactive then with fUniqueID do begin ReadOnly:=False; {gain access} AsInteger:=aValue; {set} ReadOnly:=True; {restrict access} {without passwording things} end end; function TTableUniqueIDField.GetUniqueID:LongInt; begin if State<>dsInactive then Result:=fUniqueID.AsInteger else Result:=-1; end; end.