You can reference items indirectly with the NAME_IN and COPY built-in subprograms.
The NAME_IN function returns the contents of an indicated variable or item.Use the NAME_IN function to get the value of an item without referring to the item directly.
The following statements are equivalent:
IF :emp.ename = 'smith' -- direct reference
IF NAME_IN('emp.ename') = 'smith' -- indirect reference
The return value is always a character string.To use NAME_IN for a DATE or NUMBER item, convert the string to the desired data type with the appropriate conversion function:
date_var := TO_DATE(Name_In('order.date_item'));
num_var := TO_NUMBER(Name_In('order.number_item'));
Notes on NAME_IN:
*The NAME_IN function cannot return the contents of a global or local variable.
*In PL/SQL triggers that will be executed in enter-query mode, you must use NAME_IN rather than normal bind-variable notation to access values in the data-block.(This is because the end-user mighttype relational operators into the item, producing a value which is not in a form that can be processed by PL/SQL.)
The COPY ProcedureThe COPY procedure assigns an indicated value to an indicated variable or item.Unlike standard PL/SQL assignment, however, using the COPY procedure allows you to indirectly reference the item whose value is being set:
:emp.ename := 'smith'; -- direct reference
Copy('smith','emp.ename'); -- indirect reference
COPY can be used with the NAME_IN function to assign a value to an item whose name is stored in a reference variable or item:
/* put value 'smith' in item whose name is stored in ref_item */
Copy('smith',Name_In('control.ref_item'));
Why Use Indirect ReferenceReferencing items indirectly allows you to write more generic, reusable code.By using variables in place of actual item names, you can write a subprogram that can operate on any item whose name has been assigned to the indicated variable.
Also, using indirect reference is mandatory when you refer to the value of a form bind variable (item, parameter, global variable) in PL/SQL that you write in a library or a menu module. Because libraries, menus, and forms are separate application modules, you cannot refer directly to the value of a form item in a menu-item command or library procedure.
library is not saved within form. but in different file, so there is no where to find :frm1.txt1
for example, if you have a procedure in library:
procedure p1( v_one varchar2)
name_in(v_one) to get the value inside v_one, that is :frm1.txt1, so:
copy('value', name_in(v_one)) ==> to copy value to the txt field txt1 in form frm1.
you can't use:
copy('value', :frm1.txt1), nor you can:
copy('value', v_one).
The NAME_IN function returns the contents of an indicated variable or item.Use the NAME_IN function to get the value of an item without referring to the item directly.
The following statements are equivalent:
IF :emp.ename = 'smith' -- direct reference
IF NAME_IN('emp.ename') = 'smith' -- indirect reference
The return value is always a character string.To use NAME_IN for a DATE or NUMBER item, convert the string to the desired data type with the appropriate conversion function:
date_var := TO_DATE(Name_In('order.date_item'));
num_var := TO_NUMBER(Name_In('order.number_item'));
Notes on NAME_IN:
*The NAME_IN function cannot return the contents of a global or local variable.
*In PL/SQL triggers that will be executed in enter-query mode, you must use NAME_IN rather than normal bind-variable notation to access values in the data-block.(This is because the end-user mighttype relational operators into the item, producing a value which is not in a form that can be processed by PL/SQL.)
The COPY ProcedureThe COPY procedure assigns an indicated value to an indicated variable or item.Unlike standard PL/SQL assignment, however, using the COPY procedure allows you to indirectly reference the item whose value is being set:
:emp.ename := 'smith'; -- direct reference
Copy('smith','emp.ename'); -- indirect reference
COPY can be used with the NAME_IN function to assign a value to an item whose name is stored in a reference variable or item:
/* put value 'smith' in item whose name is stored in ref_item */
Copy('smith',Name_In('control.ref_item'));
Why Use Indirect ReferenceReferencing items indirectly allows you to write more generic, reusable code.By using variables in place of actual item names, you can write a subprogram that can operate on any item whose name has been assigned to the indicated variable.
Also, using indirect reference is mandatory when you refer to the value of a form bind variable (item, parameter, global variable) in PL/SQL that you write in a library or a menu module. Because libraries, menus, and forms are separate application modules, you cannot refer directly to the value of a form item in a menu-item command or library procedure.
library is not saved within form. but in different file, so there is no where to find :frm1.txt1
for example, if you have a procedure in library:
procedure p1( v_one varchar2)
name_in(v_one) to get the value inside v_one, that is :frm1.txt1, so:
copy('value', name_in(v_one)) ==> to copy value to the txt field txt1 in form frm1.
you can't use:
copy('value', :frm1.txt1), nor you can:
copy('value', v_one).
853

被折叠的 条评论
为什么被折叠?



