Oracle Forms assigns an ID to each object that you create. An object's ID is an internal handle whose actual value is never externalized.
You can get the ID of an object by calling the Built-in FIND_ function appropriate for that object class. The FIND_ functions take a fully-qualified object name as a parameter.
In the following example, the FIND_WINDOW function is used to assign the ID of the window named my_window to the variable id_var:
DECLARE
id_var WINDOW;
BEGIN
id_var := Find_Window('my_window');
END;
Once an object ID has been assigned to a variable, you can use that variable to reference the object, rather than referring to the object by name.
For example, the syntax for the procedure RESIZE_WINDOW indicates that you can call this procedure with either a window name or window id:
Resize_Window(window_name CHAR,width
NUMBER,height NUMBER);
Resize_Window(window_id WINDOW,width NUMBER,height NUMBER);
Thus, the following calls are logically equivalent:
Resize_Window('my_window',50,35);
Resize_Window(id_var,50,35);
A FIND_ function can also be used as an actual parameter in a procedure or function call:
Resize_Window((FIND_WINDOW('my_window'),50,35);
You can mix object IDs and object names in the same parameter List, provided that each actual parameter refers to a distinct object:
Replace_Content_View(canvas_id,'window_name');
You cannot, however, use an object ID and an object name to form a fully-qualified object name:
/* invalid procedure call: */
Set_Group_Char_Cell(group_id.'column_name',1,'in_stock');
The return values of the FIND_ functions, that is, the object IDs themselves, are of a specific datatype. In the syntax example for the RESIZE_WINDOW procedure, you saw that the formal parameter window_id was declared as type WINDOW. The types for object IDs are predefined in Oracle Forms. There is a different type for each object class.
The following table shows the FIND_ function and return type for each object:
Object |
Function |
Return Type |
---|---|---|
Alert |
FIND_ALERT |
ALERT |
Block |
FIND_BLOCK |
BLOCK |
Canvas |
FIND_CANVAS |
CANVAS |
Record Group Column |
FIND_COLUMN |
GROUPCOLUMN |
Editor |
FIND_EDITOR |
EDITOR |
Form |
FIND_FORM |
FORMMODULE |
Record Group |
FIND_GROUP |
RECORDGROUP |
Item |
FIND_ITEM |
ITEM |
List of Values |
FIND_LOV |
LOV |
Menu Item |
FIND_MENU_ITEM |
MENUITEM |
Parameter List |
GET_PARAMETER_LIST |
PARAMLIST |
Relation |
FIND_RELATION |
RELATION |
Report |
FIND_REPORT_OBJECT |
REPORT |
Tab Page |
FIND_TAB_PAGE |
TAB_PAGE |
Timer |
FIND_TIMER |
TIMER |
Tree Node |
FIND_TREE_NODE |
NODE |
View |
FIND_VIEW |
VIEWPORT |
Window |
FIND_WINDOW |
WINDOW |
Before you can assign an object ID to a local variable, you must declare the variable to be of the same type as the object ID:
DECLARE
id_var WINDOW;
BEGIN
id_var := Find_Window('my_window');
IF Get_Window_Property(id_var, HEIGHT) < 25 THEN
Resize_Window (id_var, 50, 35);
END IF;
END;
There are two reasons to use object IDs in your PL/SQL code:
Each time you reference an object by name in a PL/SQL statement, Oracle Forms does the necessary processing to look up the object's ID internally. If you refer to an object by name more than once in the same trigger, Oracle Forms looks up the object's ID each time. The following trigger code references the object my_record_group three times:
DECLARE
dummy_var NUMBER;
count NUMBER;
BEGIN
dummy_var := Populate_Group('my_record_group');
count := Get_Group_Row_Count('my_record_group');
IF count > 20 THEN
Delete_Group_Row('my_record_group', ALL_ROWS);
END IF;
END;
In contrast, if you refer to an object by its ID, Oracle Forms looks up the object only once--when you call the initial FIND_ function to get the ID:
DECLARE
dummy_var NUMBER;
count NUMBER;
group RECORDGROUP := Find_Group('my_record_group');
BEGIN
dummy_var := Populate_Group(group);
count := Get_Group_Row_Count(group);
IF count > 20 THEN
Delete_Group_Row(group, ALL_ROWS);
END IF;
END;
Besides improving performance, using object IDs results in code that is easier to maintain and can be reused in other places. When you need to change the name of an object or want to reuse the same code to operate on a different object, you need only make the change in the parameter List of the initial FIND_ function, rather than in each statement that references that object.