Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 18050, TBaseTableFields class for accessing dataset fields directly

by Jim Ferguson Email: Anonymous


V1.3 Contacts.FirstName access instead of tblContacts.FieldByName('FirstName').AsString. Promotes run time field type checking in code. It Includes a procedure to generate class structures just by passing a active dataset to it.
Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 6.0  to 6.0 363 downloads
Copyright: No significant restrictions


Size: 4,849 bytes
Updated on Mon, 10 Jun 2002 15:59:16 GMT
Originally uploaded on Tue, 21 May 2002 09:52:08 GMT
SHA1 Hash: C31DDDBD066D5896F3AF742AB85DADEC58E7EFB3
MD5 Hash: AA8B2B73C0C63BF06198A91DFC406747

    Explore the files in this upload

Description
Note: The Unit Contain the procedure to genereate nessary structure.

This is a base class that you decend from to create a structure for manipulation of a dataset's current fields. It uses RTTI information there for all field declarations must be put into the published section of the decending class. Also any funny field names "Length (cm)" will still work by overriding FieldName function in the decendant. This also requires you to manage a field index which is no problem if you use an enumorated type for the index.


Example code. (Generated with table converter that is included)

type
TContactsIndex = (
cID
,cCompanyID
,cLocationID
,cFirstName
,cMiddleInitial
,cLastName
,cTitle
,cPhoneID
,cExtension
,cFaxID
,cFaxExtension
,cSoftwareVersionID
,cNoGroupMail
,cIsUser
,cIsManager
,cIsTech
,cConnectionTypeID
,cCPUName
,cEMailAddressID
);

TContactsTable = class(TBaseTableFields)
public
function FieldName(Index: TContactsIndex): String; overload;
function IsNull(Index: TContactsIndex): Boolean;
function LocateID(Value: Integer): Boolean;
published
property ID: Integer index cID read GetID; //AutoInc
property CompanyID: Integer index cCompanyID read GetID write SetID;
property LocationID: Integer index cLocationID read GetID write SetID;
property FirstName: String index cFirstName read GetString write SetString;
property MiddleInitial: String index cMiddleInitial read GetString write SetString;
property LastName: String index cLastName read GetString write SetString;
property Title: String index cTitle read GetString write SetString;
property PhoneID: Integer index cPhoneID read GetID write SetID;
property Extension: String index cExtension read GetString write SetString;
property FaxID: Integer index cFaxID read GetID write SetID;
property FaxExtension: String index cFaxExtension read GetString write SetString;
property SoftwareVersionID: Integer index cSoftwareVersionID read GetID write SetID;
property NoGroupMail: Boolean index cNoGroupMail read GetBoolean write SetBoolean;
property IsUser: Boolean index cIsUser read GetBoolean write SetBoolean;
property IsManager: Boolean index cIsManager read GetBoolean write SetBoolean;
property IsTech: Boolean index cIsTech read GetBoolean write SetBoolean;
property ConnectionTypeID: Integer index cConnectionTypeID read GetID write SetID;
property CPUName: String index cCPUName read GetString write SetString;
property EMailAddressID: Integer index cEMailAddressID read GetID write SetID;
end; //TContactsTable

implementation

// Form Declarations
private
FContacts: TContactsTable;
public
function Contacts: TContactsTable;
destructor Destroy; override;

// Methods

function .Contacts: TContactsTable;
begin
if not Assigned(FContacts) then
FContacts := TContactsTable.Create(DataSource1);
Result := FContacts
end;

destructor .Destroy;
begin
FreeAndNil(FContacts);
inherited;
end;

{ TContactsTable }

function TContactsTable.FieldName(Index: TContactsIndex): String;
begin
Result := FieldName(Ord(Index));
end;

function TContactsTable.IsNull(Index: TContactsIndex): Boolean;
begin
Result := GetIsNull(Ord(Index));
end;

function TContactsTable.LocateID(Value: Integer): Boolean;
begin
Result := DataSet.Locate(FieldName(cID),Value,[])
end;



Please let me know if this is usefull through comments on this entry.


Enjoy

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Server Response from: ETNACDC03