sx_KeyAdd

<< Click to Display Table of Contents >>

Navigation:  Apollo API Listing >

sx_KeyAdd

VB Declaration

Declare Function sx_KeyAdd Lib "Apollo9.dll"

(ByVal cpTagName as Any)

As Integer  

C Declaration

BOOL FAR PASCAL sx_KeyAdd (BYTEP cpTagname);

Description

Adds a key to the specified index order.

Note: This function can only be used on indexes that were created using the IDX_EMPTY constant for the iOption parameter of sx_Index or sx_IndexTag.

Parameters

cpTagName : The index tag the key is added into. Passing a NULL will add the key to the currently active index tag.

Return Value

True if the key was successfully added, False if not.

VB Example

iDBF = sx_Use( "c:\data\test.dbf", "test", EXCLUSIVE, SDEFOX )

iOrd = sx_Index( "test.idx", "Upper(LAST)", IDX_EMPTY, 0, &0 )

sx_GoTop

If sx_KeyAdd( 0 ) Then

MsgBox "Key added successfully."  

Else

MsgBox "Key add failed!"  

End If

C Example

/*

Maintain our own user defined conditional index.

Add or Delete all of the records to the RYO index "CUSTOM" that match the cpLastName parameter based on the bAdd parameter. Assume that there is an index called "LAST".

*/

 

Void MaintainCustom(BYTEP cpLastName, BOOL bAdd)

{

SHORT iCurOrder;

 

//Save the currently active order

iCurOrder = sx_IndexOrd();

if (bAdd) //Are we adding a key?

{

//Set the order to the "Last" tag

sx_SetOrder(sx_TagArea("LAST")):

sx_Seek(cpLastName);

while (!memcmp(cpLastName, sx_GetString("LAST"),  

strlen(cpLastName)))

{

sx_KeyAdd("CUSTOM");

sx_Skip(1);

}

//Restore the order

sx_SetOrder(iCurOrder);

}

else

{

//Set the order to the custom index

sx_SetOrder(sx_TagArea("CUSTOM"));

while (sx_Seek((BYTEP)"Smith"))

{

 sx_KeyDrop((BYTEP)caTagName);

 }

//Reset the order

sx_SetOrder(iCurOrder);

}

return;

}

See Also

sx_KeyDrop, sx_RYOKeyAdd, sx_Index, sx_IndexTag