TObjectDataSet Component

Copyright  2000 Paul Johnson (paulj@zip.com.au)
All rights reserved.



The TObjectDataset component is a TDataSet descendent that allows the published properties of objects to be accessed via data aware controls. It can be used as a replacement for the TList class where you want to display or edit a list of objects using data-aware controls.

Installation
----------

Install the ObjDS40.BPL package into Delphi and add the location of the source code to the library search path.




TObjectDataSet component

Properties
----------

ObjectClass: TClass

  The class of the objects stored in the dataset. See ObjectClassName and OnNeedClass. 




Published Properties
--------------------

DefaultStringLength: Integer

  The maximum length of long string (AnsiString) properties when accessed as a field.

ObjectClassName: string

  The name of the class of the objects stored in the dataset. The class must be registered with the RegisterClass procedure in the Classes unit.

ShareObjects: Boolean

  If ShareObjects is FALSE (default) then the objects stored in the dataset WILL be destroyed when the dataset is destroyed.




Events
------

OnCreateObject( Sender: TObject; var NewObject: TObject )

  This event occurs when a new record is inserted or added to the dataset. Create an object of the appropriate class and assign it to NewObject. If no handler is supplied for this event new objects will be created using the default Create constructor.

OnNeedClass( Sender: TObject; var ObjectClass: TClass )

  This event occurs if no ObjectClass is defined when the dataset is opened. Assign a class to ObjectClass.




Methods
-------

The Object DataSet has comparable methods to TList for the following:

  Add
  Clear
  Delete
  IndexOf
  Insert
  Remove


BeginUpdate
EndUpdate

  Use the BeginUpdate and EndUpdate to prevent the dataset from refreshing while using the TList compatible methods above.


Notes
-----

To use the Object DataSet you will need to do the following:

- Add a TObjectDataSet component to a form or datamodule.

- Set the class of the objects to be stored in the dataset using either the ObjectClass property, the ObjectClassName property or the OnNeedClass event.

- Write a handler for the OnCreateObject if you are using data-aware controls to insert or
add records.

- Add any existing objects to the DataSet at runtime using the TList compatible methods.


To get fixed length string properties define the property as a short string type of the appropriate length. Eg. For a phone number field of 10 characters:

	TPhoneNumber = string[10];

then...

	property Phone: TPhoneNumber;



The TObjectDataSet component is freeware; the source code is included. It may be freely distributed, although it must be distributed with all original files intact. It was created as an experiment in writing TDataSet descendents but perhaps someone will be able to put it to good use. Please send any questions, comments or suggestions to paulj@zip.com.au.

For anyone interested in writing a dataset, I can recommend the book 'Delphi 4 Developers Guide' by Steve Teixeira and Xavier Pacheco as a good starting point.

 




Standard Disclaimer
-------------------

This software is provided as is, without warranty of any kind, either expressed or implied. The entire risk as to the quality and performance of the software is with you.  Should the software prove defective, you assume the cost of all necessary servicing, repair, or correction.  In no event shall the author, copyright holder, or any other party who may redistribute the software be liable to you for damages, including any general, special, incidental, or consequential damages arising out of the use or inability to use the software even if the author, copyright holder, or other party has been advised of the possibility of such damages.

