version 1.5
OD Find in context (context_ID) Integer
| Parameter | Type | Description | |
| context_ID | Longint | Context identifier | |
| Function result | Integer | Context row index |
Description
OD Find in context returns the context row index that matches the current values of the bound 4th Dimension objects used as a primary key.
context_ID must be an identifier of an already activated context. A primary key must have been specified in the context definition.
OD Find in context returns a positive row index if the current values match an existing context row.
OD Find in context returns 0 if no context row matches the current values.
OD Find in context returns -1 if an error occurred (e.g., "Context has no primary key specified").
Examples
(1) The following example uses a context to load Oracle rows into 4th Dimension records. MODIFY SELECTION is called to let you sort, search, and modify the records inside 4th Dimension. Whenever you double-click a record to modify it, the corresponding row on the Oracle server is updated by this form method:
Case of : (Before) `Find the context row that matches this 4D record vIndex:=OD Find in context (ID_Context) If (vIndex>0) `This 4D record matches an existing context row, `so set the current context row to the one you found $rc:=OD Goto in context (ID_Context;vIndex) End if : (After) If (vIndex>0) `We are going to modify a 4D record that matches an existing context row, `so let's modify the corresponding Oracle row as well $rc:=OD Update in context (ID_Context) Else `This 4D record does not exist on Oracle `Here, we choose to create it on Oracle $rc:=OD Insert in context (ID_Context) End if End case
This method works even after you make a subselection of records or a sort, for example. This allows great flexibility when working with Oracle data replicated in 4th Dimension.
(2) The following example uses OD Find in context to allow you to search a record among the records of a particular context:
C_LONGINT (vEmpno)
C_TEXT (vEname)
ID_Context:=OD Create context ("scott.emp")
OD ADD TO CONTEXT (ID_Context;"empno";»vEmpno;kKey)
OD ADD TO CONTEXT (ID_Context;"ename";»vEname)
`Activate the context and load the primary key values (the empno column values)
$rc:=OD Activate context (ID_Login;ID_Context;1)
Repeat
vEmpno:=Num (Request ("Enter an employee number:"))
If (OK=1)
$index:=OD Find in context (ID_Context)
If($index>0)
$rc:=OD Goto in context (ID_Context;$index)
ALERT ("Employee name is: "+vEname)
Else
ALERT ("There is no employee with this number.")
End if
End if
Until (OK=0)
OD DROP CONTEXT (ID_Context)
See Also
OD ADD TO CONTEXT, OD Goto in context.