TableSetIndex

Top  Previous  Next

Prototype

 

TableSetIndex(intTableHandle,strFieldName)

 

Description

 

Sets the field where the table will be ordered

 

Parameters

 

IntTableHandle: integer value corresponding to the table handle.

 

StrFieldName: string corresponding to the field name.

 

Returned value

 

None.

 

Notes

 

If the table is local (Paradox, dBase, FoxPro, Access) there will be also an index on the field. The TableFind and TableFindNearest commands use the selected field with this function.

 

Example

 

// open a table

TableOne:=TableOpenBDE('c:\invoices\index','invoices.db'); 

 

name:=TablegetFieldname(TableOne,1);

 

// Orders the table according to a field

TableSetIndex(TableOne, name); 

 

// Store the index 1 field data

FieldValue:='Smith';

 

// Search for data within the table and places itself on the record

TableFindNearest(TableOne,FieldValue);

 

// Store the table field value into a variable

FoundValue:=TableGetField(TableOne,1);

 

// If the table value is different than the field one then…

If FoundValue<>FieldValue Then

Begin

 

// Set the table insert mode

TableInsert(TableOne);

 

// Store the field value in a new record

TableSetField(TableOne,1,FieldValue);

 

// Confirm the table change

TablePost(TableOne);

End;

 

// Close the table

TableClose(TableOne);