{ LnkCrsr.pas } program LnkCrsr; {$IfDef VER80} uses SnipTool, SnipData, SysUtils, WinTypes, WinProcs, DbiProcs, DbiTypes, DbiErrs; {$Else} uses WinTypes, WinCrt, Strings, DbiProcs, DbiTypes, DbiErrs, SnipTool, SnipData; {$EndIf} const szMasterTable = 'customer'; { Name of master table } szDetailTable = 'orders'; { Name of the detail table } szTblType = szPARADOX; { Table type to use. } {===================================================================== Code: LnkCrsr(); Input: None. Return: None. Description: Linking cursors establishes a link between two cursors such that the detail cursor has its record set limited to the set of records matching the linking key values of the master cursor. ===================================================================== } var hDb: hDBIDb; { Handle to the Database } hCurMaster: hDBICur; { Handle to the master table } hCurDetail: hDBICur; { Handle to the detail table } const uNumRecs: UINT32 = 10; { Number of records to display, 0 := all } uFieldsMaster: UINT16 = 1; { Link the first field of Customer } uFieldsDetail: UINT16 = 2; { To the second field of Orders (Which is indexed) } begin Screen('*** Linked Cursor Example ***'); Screen(' Initializing the engine...'); if (InitAndConnect(hDb) <> DBIERR_NONE) then { Terminate example if } begin { Initialization fails } Screen(''); Screen('*** End of Example ***'); exit; end; Screen(' Setting the default Database directory...'); ChkRslt(DbiSetDirectory(hDb, pCHAR(szTblDirectory)), DBIERR_NONE, ' Error - SetDirectory.'); Screen(' Open the "'+szMasterTable+'" master table...'); if (ChkRslt(DbiOpenTable(hDb, pCHAR(szMasterTable), pCHAR(szTblType), nil, nil, 0, dbiREADWRITE, dbiOPENSHARED, xltFIELD, FALSE, nil, hCurMaster), DBIERR_NONE, ' Error - OpenTable.') <> DBIERR_NONE) then begin CloseDbAndExit(hDb); Screen(''); Screen('*** End of Example ***'); exit; end; Screen(' Display the first 10 records of the "'+szMasterTable+'" ' + 'master table...'); ChkRslt(DisplayTable(hCurMaster, uNumRecs), DBIERR_NONE, ' Error - DisplayTable.'); Screen(' '); Screen(' Open the "'+szDetailTable+'" detail table...'); if (ChkRslt(DbiOpenTable(hDb, pCHAR(szDetailTable), pCHAR(szTblType), nil, nil, 0, dbiREADWRITE, dbiOPENSHARED, xltFIELD, FALSE, nil, hCurDetail), DBIERR_NONE, ' Error - OpenTable.') <> DBIERR_NONE) then begin CloseDbAndExit(hDb); Screen(''); Screen('*** End of Example ***'); exit; end; Screen(' Display the first 10 records of the "'+szDetailTable+'" ' + 'detail table...'); ChkRslt(DisplayTable(hCurDetail, uNumRecs), DBIERR_NONE, ' Error - DisplayTable.'); Screen(''); Screen(' Set to the Customer_No index on the detail table...'); ChkRslt(DbiSwitchToIndex(hCurDetail, nil, nil, 2, FALSE), DBIERR_NONE, ' Error - SwitchToIndex.'); Screen(' Link the tables...'); { Put the Customer table into link mode } ChkRslt(DbiBeginLinkMode(hCurMaster), DBIERR_NONE, ' Error - BeginLinkMode.'); { Put the Orders table into link mode } ChkRslt(DbiBeginLinkMode(hCurDetail), DBIERR_NONE, ' Error - BeginLinkMode.'); { Link the two tables, specifying which fields will be linked in the last two parameters. Specifically, link the first field of Customers to the indexed second field of Orders } ChkRslt(DbiLinkDetail(hCurMaster, hCurDetail, 1, @uFieldsMaster, @uFieldsDetail), DBIERR_NONE, ' Error - LinkDetail.'); Screen(' Display the "'+szDetailTable+'" detail table after the link:'); Screen(' Note that all Customer No''s correspond to the last'); Screen(' record displayed in the master table.'); ChkRslt(DisplayTable(hCurDetail, uNumRecs), DBIERR_NONE, ' Error - DisplayTable.'); Screen(''); Screen(' End the link...'); { Unlink the detail table from the master table } ChkRslt(DbiUnlinkDetail(hCurDetail), DBIERR_NONE, ' Error - EndLinkMode.'); { Take the Customer table out of link mode } ChkRslt(DbiEndLinkMode(hCurMaster), DBIERR_NONE, ' Error - EndLinkMode.'); { Take the Orders table out of link mode } ChkRslt(DbiEndLinkMode(hCurDetail), DBIERR_NONE, ' Error - EndLinkMode.'); Screen(' Close the tables...'); { Close the Master table } ChkRslt(DbiCloseCursor(hCurMaster), DBIERR_NONE, ' Error - CloseCursor.'); { Close the detail table } ChkRslt(DbiCloseCursor(hCurDetail), DBIERR_NONE, ' Error - CloseCursor.'); Screen(' Close the Database and exit IDAPI...'); CloseDbAndExit(hDb); Screen('*** End of Example ***'); end.