TableSetIndex
Previous  Top  Next

Prototype

TableSetIndex
(intTableHandle,strFieldName)

Description

It 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

//It opens a table
UnaTabella:=TableOpen('c:\invoices\index','invoices.db'); 

name:=TablegetFieldname(UnaTabella,1);

//It orders the table according to a field
TableSetIndex(UnaTabella, name); 



//It stores the index 1 field data
FieldValue:='Smith';

//It looks for data within the table and places itself on the record
TableFindNearest(UnaTabella,FieldValue);

//It stores the table field value into a variable 
FoundValue:=TableGetField(UnaTabella,1);

// If the table value is different than the field one then…
If FoundValue<>FieldValue Then
Begin

//It sets the table insert mode   
TableInsert(UnaTabella);  
 
//It stores the field value in a new record  
TableSetField(UnaTabella,1,FieldValue);  
 
//It confirms the table change   
TablePost(UnaTabella);  
End;

// It closes the table
TableClose(UnaTabella);