Object Manager Contents

Welcome to the Object Manager.

Start Here

Building an Object

Generating the source code

Supplied files

Author

Current Version

See also the important note on inheritance.


Supplied Files

ObjMan.exe	The main executable file. Place in a directory of your choice.

ObjMan.hlp	This help file. Place in the same directory as ObjMan.exe.

Unit.skl	The class skeleton source file. Place in the same directory as ObjMan.exe.

TSObjectU.dcu	The TSObject compiled unit. Place in a directory where Delphi can access it.


Beginner's Guide to Object Manager

In building a database application or suite of applications for a client the developer will create a number of new classes (or objects). These objects will undertake a number of tasks and it is the developer's responsibility to ensure that the maintenance of these objects is undertaken correctly and new objects are not created when existing ones can be used and further developed or used as a new parent.

The Object Manager was created to undertake such a task. It is designed to keep in one place all the objects that are used in a specific project. A master object has been created and is supplied with Object Manager. This master object is a derivative of TObject and is called TSObject. All objects in every project maintained by Object Manager is derived from the TSObject base class.

The Object Manager allows you to create a new object (derived from TSObject), add fields, procedures and functions to the object. You can derive from your own objects ad infinitum, all the derived objects have the fields, procedures and functions avialable from their parents.

The TSObject class has built in database handling and date routines. These will ensure that the programmer can leave the data manipulation and table maintenance entirely to the object itself.

Each project is kept within its own area within Object Manager. A new project is defined to Object Manager by selecting Project New Project.

All objects are held within the main Object Manager database and the source code produced by Object Manager will be kept in a sub-directory of Object Manager with the same name as the project.

See also the important note on inheritance.


Building an Object

The steps involved in building your own object(s) from the start are as follows.

1. Create a new project

2. Add an object to the TSObject class

3. Define the fields for the object

4. Define the functions and procedures for the object

5. Build the source code (generate)

The steps involved in building your own object(s) from within an existing project are as follows.

1. Select the project that you wish to work with

2. Add your new object to any of the existing classes

3. Define the fields for the object

4. Define the functions and procedures for the object

5. Build the source code (generate)


Select a Project

This is done by using the master menu option Project Open Project.


Create a new project

This is done by using the master menu option Project New Project.


Add new object

This is done from the master menu option Object New Object.


Add New Field

This is done from the master menu option Object New Field.


Add functions/procedures

This is done from the master menu option Object New Procedure or Object New Function.


Build Source Code

This is done from the master menu option File Build Source File(s).


Generating the source code

Object Manager will build source code for each of the new objects/classes that you have defined.

This is done by using the menu option File Build Source File(s). A dialog box will be displayed that shows you two list boxes, one on the left and one on the right.

The listbox on the left shows the objects that Object Manager thinks should be rebuilt. The listbox on the right shows those objects that you have chosen to build in this session. To transfer a file from the left to right and vice versa is simply a matter of highlighting the appropriate file and clicking on the '>>' or '<<' button.

When you are ready click on the 'Build' button and Object Manager will build the source code for the selected objects.

The source code will be placed in a sub directory of your Object Manager directory. This sub-directory will have the name of your Project.


Author

This software has been produced by:

Simon Berridge

100 Seymour Park Road

Marlow

Buckinghamshire

SL7 3EW

For help and support contact by email at SimonBerridge@compuserve.com

Registration of this software may be done via Compuserve's SWREG facility. GO SWREG and search for an ID of 14707.


TSObject

TSObject is the master object from which all of your new objects will be derived.

Object Manager will create a source file for each of your new objects and maintain the database housekeeping for you. This is all done from within TSObject.

Construction of a TSObject derived class

Destruction of a TSObject derived class

Properties of TSObject

Variables within TSObject

TSObject available procedures

TSObject available functions


Construction of a TSObject derived class

constructor Create(Nm : shortstring);

All of your derived classes will have the above Constructor overridden.

The correct syntax in constructing a derived object is as follows:

var

  MyObject : TSomething;

  MyObject := TSomething.Create('TSomething');

TSomething is a class that has been derived from TSObject. It may not be a direct derivative of TSObject but TSObject will be the master object. To create the correct database entries and maintain the object correctly TSObject needs to know the bottom object name, this is why it is passed via the Create construct at run-time.

It is very important that the same name as the derived class is passed back at all times otherwise you will obtain a new database with a different name.


Destruction of a TSObject derived class

destructor Destroy; override;

Destruct your object by calling the Destroy method.


Properties of TSObject

At the TSObject level there are two properties held:

property MyName

property RecordPointer

property TableDirectory

In your derived objects each field will have a property associated with it. Each specified field within your derived object will have the name 'f' + your field name.

An example would be:

You have defined a field called Surname. The property of this field will be Surname but the internal field within the object will be fSurname.


MyName Property

property MyName : string

This property is a string field and holds the name of the property.

This property is set in the Create construction.


RecordPointer Property

property RecordPointer : longint

This property points to the current database record in memory.

In your program code you can move to a specific record (if you know its record number) by setting this property:

   MyObject.RecordPointer := 26;

The above statement would access the database and retrieve record number 26. If the record does not exist then the value in RecordPointer will not change. It would be good programming practice to set a local variable to the value of RecordPointer before executing the above code to ensure that the read was undertaken. For example:

var

  RecNum : longint;

  with MyObject do

  begin

    RecNum := RecordPointer;

    RecordPointer := 26;

    if RecordPointer = RecNum then

      failed to retrieve

  end;


Variables within TSObject

There is one variable that is of use to the programmer, the ReturnList variable.

ReturnList is an instance of a TStringList object. It is in this variable that the results of a GetList procedure call are returned.


ReturnList

ReturnList is a property of TSObject. It holds the values returned from a GetList call.

The return values are returned within the TSObject ReturnList variable. This is a TStringList variable.

Read the result of a call to GetList with the following code:

for loop := 0 to ReturnList.Count - 1 do

begin

  MyObject.RecordPointer := StrToInt(ReturnList.Strings[loop]);

  ... processing on MyObject

end;

Alternatively you can use the ListNumber function within TSObject. This function converts the string value within ReturnList to a long integer value that can be directly used. Example code:

for loop := 0 to ReturnList.Count - 1 do

begin

  MyObject.RecordPointer := MyObject.ListNumber(loop);

  ... processing on MyObject

end;


TSObject available procedures

There are two procedure calls available within TSObject:

GetList

FindRecord


GetList function
GetList procedure

procedure GetList(Lst : TStringlist);

The GetList procedure resturns a list (in ReturnList) of the records that match the criteria sent within the Lst string list parameter. The Lst parameter is an SQL statement, omitting the where clause.

An example would be if you are seraching for a match on surnames like "Smith". The appropriate code would be:

with MyList do

begin

  Clear;

  Add('Surname like "%Smith%"');

  Add('order by Surname, FirstName');

end;

GetList(MyList);

If the underlying table name is 'TPerson' then the above code would be equivalent to sending the following message to the table:

SELECT * FROM TPerson

WHERE

Surname like "%Smith%"

order by Surname, FirstName

TSObject will always place a 'select * from Database where' SQL statement before the lines submitted in your own list.

The return values are returned within the TSObject ReturnList variable. This is a TStringList variable.

Read the result with the following code:

for loop := 0 to ReturnList.Count - 1 do

begin

  MyObject.RecordPointer := StrToInt(ReturnList.Strings[loop]);

  ... processing on MyObject

end;

Alternatively you can use the ListNumber function within TSObject. This function converts the string value within ReturnList to a long integer value that can be directly used. Example code:

for loop := 0 to ReturnList.Count - 1 do

begin

  MyObject.RecordPointer := MyObject.ListNumber(loop);

  ... processing on MyObject

end;


FindRecord procedure

procedure FindRecord(Lst : TStringlist);

The FindRecord procedure will return within your instance the result of the find. The Lst variable will hold an SQL statement that will enable you to pinpoint a specific record. If you cannot narow the search down to retrieving a specific record use GetList instead.

For a discussion on the usage of Lst see the GetList procedure.


TSObject available functions

There are two types of functions within TSObject, record handling and date handling.


Record Handling within TSObject

The following functions are available within TSObject:

function WriteRecord : boolean;

function GetNextRecord : boolean;

function GetFirstRecord : boolean;

function GetPreviousRecord : boolean;

function UpdateRecord : boolean;

function DeleteRecord : boolean;

function ListNumber : longint;


WriteRecord function

function WriteRecord : boolean;

This function will write the contents of the fields within the object to the database as an Append, i.e. it will add a new record to the database.

Example:

with MyObject do

begin

  Surname := 'Smith';

  FirstName := 'John';

  DateOfBirth := StrToDate('12/05/65');

  if WriteRecord then

  .. record written OK

end;


GetNextRecord function

function GetNextRecord : boolean;

This function returns the next record in the database. It is normally used following a GetFirstRecord call.

Example:

with MyObject do

begin

  if GetFirstRecord then

    repeat

      .. processes

    until not GetNextRecord;

end;


GetFirstRecord function

function GetFirstRecord : boolean;

Use this function to access the first record in the database and return the values in the object fields.

Example:

with MyObject do

begin

  if GetFirstRecord then

    repeat

      .. processes

    until not GetNextRecord;

end;


GetPreviousRecord function

function GetPreviousRecord : boolean;

This function works in the same way as the Table.Prior function.


UpdateRecord function

function UpdateRecord : boolean;

This function will write the existing record in memory to the database and update the old record with the new record.


DeleteRecord function

function DeleteRecord : boolean;

This function deletes the current record in memory from the database.


ListNumber function

function ListNumber(Num : integer) : longint

The ListNumber function within TSObject converts the string value within ReturnList to a long integer value that can be directly used. Example code:

for loop := 0 to ReturnList.Count - 1 do

begin

  MyObject.RecordPointer := MyObject.ListNumber(loop);

  ... processing on MyObject

end;

If ReturnList does not hold\any values then ListNumber returns -1.


Date Handling within TSObject

The following date handling routines are available within TSObject:

function LongDate(Dt : TDateTime) : shortstring;

function FullDate(Dt : TDateTime) : shortstring;

function Weekend(Dt : TDateTime) : boolean;

function AddWeek(Dt : TDateTime) : TDateTime;

function AddMonth(Dt : TDateTime) : TDateTime;

function AddQuarter(Dt : TDateTime) : TDateTime;

function AddHalfYear(Dt : TDateTime) : TDateTime;

function AddYear(Dt : TDateTime) : TDateTime;

function MinusWeek(Dt : TDateTime) : TDateTime;

function MinusMonth(Dt : TDateTime) : TDateTime;

function MinusQuarter(Dt : TDateTime) : TDateTime;

function MinusHalfYear(Dt : TDateTime) : TDateTime;

function MinusYear(Dt : TDateTime) : TDateTime;

function LongTime(Dt : TDateTime) : shortstring;

function FullTime(Dt : TDateTime) : shortstring;

function AddHours(Tm : TDateTime; Hrs, Mins : word) : TDateTime;

function MinusHours(Tm : TDateTime; Hrs, Mins : word) : TDateTime;

function BusinessDays(Dt1,Dt2 : TDateTime) : integer;


LongDate function

function LongDate(Dt : TDateTime) : shortstring;

This function will return a string representation of a TDateTime value.

Dt := StrToDate('27/05/97');

Label1.Caption := LongDate(Dt);

Label1.Caption will hold the string value '27 May 1997'.


FullDate function

function FullDate(Dt : TDateTime) : shortstring;

This function will return a string representation of a TDateTime value.

Dt := StrToDate('27/05/97');

Label1.Caption := FullDate(Dt);

Label1.Caption will hold the string value 'Tuesday 27 May 1997'.


Weekend function

function Weekend(Dt : TDateTime) : boolean;

This function returns true if the supplied date is a Saturday or Sunday and false if it is a Monday to Friday.


AddWeek function

function AddWeek(Dt : TDateTime) : TDateTime;

This function adds one week to the supplied date.


AddMonth function

function AddMonth(Dt : TDateTime) : TDateTime;

This function adds one month to the supplied date.


AddQuarter function

function AddQuarter(Dt : TDateTime) : TDateTime;

This function adds one quarter to the supplied date.


AddHalfYear function

function AddHalfYear(Dt : TDateTime) : TDateTime;

This function adds one half year (6 months) to the supplied date.


AddYear function

function AddYear(Dt : TDateTime) : TDateTime;

This function adds one year to the supplied date.


MinusWeek function

function MinusWeek(Dt : TDateTime) : TDateTime;

This function takes one week away from supplied date.


MinusMonth function

function MinusMonth(Dt : TDateTime) : TDateTime;

This function takes one month away from supplied date.


MinusQuarter function

function MinusQuarter(Dt : TDateTime) : TDateTime;

This function takes one quarter (3 months) away from supplied date.


MinusHalfYear function

function MinusHalfYear(Dt : TDateTime) : TDateTime;

This function takes one half year (6 months) away from supplied date.


MinusYear function

function MinusYear(Dt : TDateTime) : TDateTime;

This function takes one year away from supplied date.


LongTime function

function LongTime(Dt : TDateTime) : shortstring;

This function returns a string representation of the time passed in the format 'hh:nn am/pm'.


FullTime function

function FullTime(Dt : TDateTime) : shortstring;

This function returns a string representation of the time passed in the format 'hh:nn:ss am/pm'.


AddHours function

function AddHours(Tm : TDateTime; Hrs, Mins : word) : TDateTime;

This function returns the time value of the passed time (Tm) added to the Hours(Hrs) and Minutes(Mins) passed.


MinusHours function

function MinusHours(Tm : TDateTime; Hrs, Mins : word) : TDateTime;

This function returns the result of taking the time(Tm) passed and taking the hours(Hrs) and minutes(Mins) away.


BusinessDays function

function BusinessDays(Dt1,Dt2 : TDateTime) : integer;

This function returns the number of business dayes between two dates.

A business day is defined as a day between Monday and Friday inclusive. Note that it does not take into consideration bank or public holidays.


TableDirectory property

property TableDirectory : string

The TableDirectory property is the DataBaseName of the underlying table created by TSObject.

By default this will be set to the filepath of the application executable program plus '\DATA'. If you wish the directory to be elsewhere then set the TableDirectory immediately after construction of your object.

Example:

var

  MyObject : TDerivedObject;

begin

  MyObject := TDerivedObject.Create('DATA01');;

  MyObject.TableDirectory := 'c:\myapps\project3\database';

end;


Field Maintenance Window

This window is where the majority of your work will be carried out.

Enter the name of the field (do not prefix the name with 'f' as this will be done by Object Manager). Select the type of field from the drop-down combo box.

Depending upon the type of field selected a panel may be displayed in the bottom left hand corner of the window requesting additional information. For example, a string field (shortstring or string) will display a Field Length entry field.

In essence, this window is similar to entering fields into the Database manager, the type and length(s) are required. There are two special field types within this drop-down list

object

and	TypeCast

There are two check boxes on this window, one marked Database and the other marked Private. The Database check box is on by default and advises Object Manager that this field is to be a field that is read and written to the database file. The Private check box will place the field within the private section of the class object and will not be written to the database, regardless of the state of the Database check box.

There are two buttons, one marked Read and the other marked Write. Pressing one of these buttons will bring up either the Read Procedure or Write Procedure dialog box.


Object

This field type definition points Object Manager to one of your own defined objects.

The source code produced for the new object will include a reference to your object and will create and destroy the object automatically. All you need to do is reference the field name as though it is your object.


TypeCast

TypeCast field definition will allow you to point to a type that you have previously defined from the Project Define Type option from the top menu.


Read/Write Procedures

A dialog box will be displayed, shown above.

In this dialog box enter the program code associated with the Read or Write procedure for the field. This program code is copied exactly as you enter it within the begin..end construct of the procedure so care should be taken in this area.


Type Casting

Object Manager requires that you define your own types. This is done from the Project Define Type option from the master menu.

A dialog box is displayed, shown below:

You may add, change or delete your defined types from this window.

A further dialog box will be opened, an example shown below:


Build Source

The build source window displayed shows you two list boxes, one on the left and one on the right.

The listbox on the left shows the objects that Object Manager thinks should be rebuilt. The listbox on the right shows those objects that you have chosen to build in this session. To transfer a file from the left to right and vice versa is simply a matter of highlighting the appropriate file and clicking on the '>>' or '<<' button.

When you are ready click on the 'Build' button and Object Manager will build the source code for the selected objects.

The source code will be placed in a sub directory of your Object Manager directory. This sub-directory will have the name of your Project.

This function is described more fully in the section headed Generating the Source Code.


Inheritance

Each object that is defined inherits the fields and procedures/functions defined in its parent. As every object has, as its ultimate parent, TSObject, all the fields and procedures/functions within TSObject are inherited.

When you define a new field, procedure or function within one of your own classes, any subsequent classes derived from your own base class will, of course, inherit those attributes. However, you may wish to override the subsequent instance to return a different value.

This is done simply by redefining the attribute in the new class by giving it the same name. It is important to note that Object Manager will always override its parent attribute. If you wish to use the inherited function before or after your own function it is your responsibility to place the 'inherited' keyword and its use within the body of the procedure/function/read/write as you see fit.


Current Version

The version you are using is Version 1.2, released in March 1997.

Contact the author for the latest version information.

email: SimonBerridge@compuserve.com