A base class object that represents a field from a table and can be used as a calculated field.

Syntax

[<oRef> =] new Field( )

<oRef>

A variable or property in which to store the reference to the newly created Field object for use as a calculated field.

Properties

The following tables list the properties, events. and methods of the Field class. For details on each property, click on the property below.

Property

Default

Description

baseClassName

FIELD

Identifies the object as an instance of the Field class

className

(FIELD)

Identifies the object as an instance of a custom class. When no custom class exists, defaults to baseClassName

fieldName

 

Name of the field the Field object represents, or the assigned calculated field name

length

 

Maximum length

logicalSubType

 

A database independent name indicating the data subtype of a value stored in a field

logicalType

 

A database independent name indicating the data type of a value stored in a field

lookupRowset

 

Reference to lookup table for field

lookupSQL

 

SQL SELECT statement for field lookup values

parent

null

fields array that contains the object

type

Character

The field’s data type

value

Empty string

Represents current value of field in row buffer

 

Event

Parameters

Description

beforeGetValue

 

When value property is to be read; return value is used as value

canChange

<new value>

When attempting to change value property; return value allows or disallows change

onChange

 

After value property is successfully changed

onGotValue

 

After value is read

 

Method

Parameters

Description

copyToFile( )

<filename expC>

Copies data from BLOB field to external file

replaceFromFile( )

<filename expC>
[, <append expL>]

Copies data from external file to BLOB field

Description

The Field class acts as the base class for the DbfField (dBASE), PdxField (Paradox), and SqlField (everything else) classes. It contains the properties common to all field types. Each subclass contains the properties specific to that table type. You also create calculated fields with a Field object.

Each rowset has a fields property, which points to an array. Each element of that array is an object of one of the subclasses of the Field class, depending on the table type or types contained in the rowset. Each field object corresponds to one of the fields returned by the query or stored procedure that created the rowset.

While the fieldName, length, and type properties describe the field and are the same from row to row, the value property is the link to the field’s value in the table. The value property’s value reflects the current value of that field for the current row in the row buffer; assigning a value to the value property assigns that value to the row buffer. The buffer is not written to disk unless the rowset’s save( ) method is explicitly called or there is an implicit save, which is usually caused by navigation in the rowset. You can abandon any changes you make to the row buffer by calling the rowset’s abandon( ) method.

You may assign a Field object to the dataLink property of a control on a form. This makes the control data-aware, and causes it to display the current value of the Field object’s value property; if changes are made to the control, the new value is written to the Field object’s value property.

Calculated fields

Use a calculated field to generate a value based on one or more fields, or some other calculation. For example, in a line item table with both the quantity ordered and price per item, you can calculate the total price for that line item. There would be no need to actually store that total in the table, which wastes space.

Because a calculated field is treated like a field in most respects, you can do things like dataLink it to a control on a form, show it in a grid, or use it in a report. Because a calculated field does not actually represent a field in a table, writing to its value property directly or changing its value through a dataLinked control never causes a change in a table.

To create a calculated field, create a new Field object and assign it a fieldName, then add( ) it to the fields array of a Rowset object.

Morphed and calculated fields sometimes require display widths that are larger than their field widths. To avoid truncating the display, use a picture that represents the field’s maximum size.

Note You must assign the fieldName before adding the field to the fields array.

Because a rowset is not valid until its query opens, you must make the query active before you add the Field object. The query’s onOpen event, which fires after the query is activated, is a good place to create the calculated field. To set the value of a calculated field, you can do one of two things

Assign a code-reference, either a codeblock or function pointer, to the Field object’s beforeGetValue event. The return value of the code becomes the Field object’s value.

Assign a value to the Field object’s value property directly as needed, like in the rowset’s onNavigate event.