sx_SetRelation

<< Click to Display Table of Contents >>

Navigation:  Apollo API Listing >

sx_SetRelation

VB Declaration

Declare Sub sx_SetRelation Lib "Apollo9.dll"

(ByVal uiChildArea As Integer,

ByVal cpKeyExpr As String)

Description

Defines a relationship between the current table and another table. The current table is the parent. The related table is the child. The relationship between the parent and the child must be many (parent) to one (child) or one to one.

 

The parent file must be the active table when sx_SetRelation is called.

Parameters

uiChildArea: This is the work area identifier of the child file that is returned by sx_Usewhen the file is opened. The child file must have an active index in order to set up a relationship.

cpKeyExpr: Defines an xBase expression that will be used to construct a key from parent data into the active child index.

When a record movement occurs in the parent file, a pending relational move is posted to the child file work area. If the child data must be accessed (which is forced by a field reference to it, for example), a key is first constructed from the parent data by evaluating cpKeyExpr and then performing sx_Seek on the child file. Relational moves do not respect the settings of sx_SetExact and sx_SetSoftSeek.

If a relational move is posted to a child file and the seek for the key fails, the child file record pointer is set to EOF, as are any children in its relational chain. If the seek is successful, sx_Found will return True for the child area.

More than one relationship may be set up for a given parent file (no limit), and child files may themselves be parents to other relationships. Circular references in the relational chain are of course forbidden (unless you enjoy infinite looping as a pastime).

Note: To clear relations in the current work area, pass uiChildArea as zero and pass a space in the cpKeyExpr parameter.

VB Example

' Open the child table

iPartsDbf = sx_Use( "c:\data\parts.dbf", "parts", READWRITE, SDENTX )

iPartsNtx = sx_IndexOpen( "c:\data\parts1.ntx" )

 

' Open the parent table

iSerDbf = sx_Use( "c:\data\serial.dbf", "serial", READWRITE, SDENTX )

iSerNtx = sx_IndexOpen( "c:\data\serial1.ntx" )

 

' Set up relationship

Call sx_SetRelation( iPartsDbf, "part_num" )

 

' Display the first record

sx_GoTop

BoxPartNum.Text = sx_GetString( "part_num" )

See Also

sx_SetScope