Oracle Forms 10g release 2 : Demos, Tips and Techniques

Home page

1. Introduction Here is a collection of Oracle Forms 10g sample dialogs extracted from a complete Oracle Forms tutorial. This tutorial has been written in French and it would be too time consuming to translate it all in English. This is the reason why I have only extracted and translated these sample dialogs. The purpose of this article is not to teach how to build a new form from scratch. It intends to show some of the main advanced features of the product. To clearly understand in details how these dialogs work, you will have to open them in the Forms Builder and examine them thoroughly. However, in this article, I am going to explain the best I can the most important mechanisms of each sample. These sample have been tested with an Oracle Forms 10g release 10.1.2.0.2 on an Oracle Database 10g Express Edition Release 10.2.0.1.0.

2. Description of the sample dialogs

2.1 Main screen

TUTO_FORMS.FMB

This dialog is the entry point of the samples. Click on a button to start the corresponding dialog.

2.2 Canvases

TEST_CANVAS.FMB

This sample shows three types of canvas :    The content canvas (light green) The stacked canvas (white) The tab canvas (dark green)

Stacked canvas A stacked canvas is displayed atop—or stacked on—the content canvas assigned to the current window. Stacked canvases obscure some part of the underlying content canvas, and often are shown and hidden programmatically. You can display more than one stacked canvas in a window at the same time A stacked canvas allows to scroll a big canvas in a delimited window. In this sample, the stacked canvas (CV_EMP_1) is twice bigger than its viewport. The <Down> button allows to move the stacked canvas programatically:
Set_View_Property('CV_EMP_1', VIEWPORT_Y_POS_ON_CANVAS, 140) ;

Here are the properties of this stacked canvas: Viewport Viewport X position Viewport Y position Viewport Width Viewport Height 77 11 212 138 Physical Viewport X position on canvas 0 Viewport Y position on canvas 0 Width 212 Height 324 The second Stacked canvas (CV_EMP_3) demonstrates how to integrate in a Tab canvas: .

The code that handles the target table is located in a program unit. DEPT and EMP) and when you can insert. called from the three blocklevel triggers:    ON-INSERT ON-UPDATE ON-LOCK .2. update and delete from the target tables from this view.1 Block based on a complex view TEST_BLOC_VUE.3.3 Blocks 2.FMB This sample show how you can base a block on a view that aggregate the columns of several tables (in this case.

End . :EMP_DEPT. -. ENAME ) VALUES ( :EMP_DEPT. Exception When no_data_found Then -.EMPNO ) .This is the code of the ins_upd_emp_dept procedure: PROCEDURE ins_upd_emp_dept IS LN$Dummy PLS_INTEGER := 0 . BEGIN -.DEPTNO . DNAME ) VALUES ( :EMP_DEPT. -.Table EMP -Begin Select 1 Into LN$Dummy From DUAL Where exists( select empno from emp where empno = :EMP_DEPT.Not found -> insert -Message('Insert into EMP table'). END.EMPNO .DEPTNO ) . .DNAME WHERE DEPTNO = :EMP_DEPT. Exception When no_data_found Then -. INSERT INTO EMP ( EMPNO. UPDATE DEPT SET DNAME = :EMP_DEPT.Found -> update -Message('Update DEPT table'). End .Not found -> insert -Message('Insert into DEPT table'). INSERT INTO DEPT ( DEPTNO.Table DEPT -Begin Select 1 Into LN$Dummy From DUAL Where exists( select deptno from dept where deptno = :EMP_DEPT. UPDATE EMP SET ENAME = :EMP_DEPT. -. :EMP_DEPT.EMPNO.DNAME ) .Found -> update -Message('Update EMP table').ENAME ) .ENAME WHERE EMPNO = :EMP_DEPT.DEPTNO.

3.2.FMB This sample demonstrates how a block can be based on stored procedures. . This feature can be implemented in two ways:   A REF CURSOR A PL/SQL table In addition to that. there are also two different locations where to implement this functionality:   The ON-xxx triggers The transactionnal triggers In this sample.2 Block based on stored procedures TEST_BLOC_PROC. the top block uses a REF CURSOR with the ON-xxx triggers The bottom block uses a collection with the standard transactionnal triggers.

empno LR$Emp.empno%TYPE.sal%TYPE.job%TYPE. r. comm emp.job.job LR$Emp. delete and lock orders are managed in the corresponding On-xxx triggers: Example of ON-INSERT trigger: DECLARE LR$Emp emp_pkg. job. END emp_insert. job emp. REF CURSOR and ON-xxx triggers The Query Data Source Type is set to Procedure and the Query Data Source Name indicates the name of the query procedure. := := := := := :emp. ename emp.emp_insert( LR$Emp ). ename.job.Insert ------------PROCEDURE emp_insert(r IN emp_rec) IS BEGIN INSERT INTO emp (empno.The stored procedures are located in the PKG_EMP package shipped with the scripts. :emp. update. Block1 (EMP).emp_rec TYPE emp_rec IS RECORD( empno emp.comm.comm END. The variable used as parameter is of type of emp_pkg.empno. comm) VALUES(r.ename. sal. :emp.empno. :emp.sal.ename LR$Emp. emp_pkg.sal. The insert.emp_rec. Then the emp_pkg. r.comm).comm%TYPE).sal LR$Emp. sal emp. r.ename%TYPE. BEGIN LR$Emp. r. .emp_insert() stored procedure: ------------.ename. :emp.

LOOP FETCH empselect INTO emp_data( ii ).empno. sal.sal.comm. emp_data( ii ). END emp_query. (see them in detail in the EMP_PKG package) Have also a look at the Query Data Source Column property that manages the relation between the columns of the collection and the items of the block. ii := ii + 1. EXIT WHEN empselect%NOTFOUND. emp_data( ii ). job.job. ename. The collection of records is an IN OUT parameter.pkg. TYPE emptab IS TABLE OF emp_rec INDEX BY BINARY_INTEGER. CURSOR empselect IS SELECT empno. emp_data( ii ). END LOOP. . Collection and transactionnal triggers This block uses a collection of records with the emp.Block2 (EMP_TRG).delete and lock orders are also managed by stored procedures. PROCEDURE emp_query(emp_data IN OUT emptab) IS ii NUMBER. ii := 1. The insert.ename. read from the database and returned to Forms. update. BEGIN OPEN empselect. emp_data( ii ). comm FROM emp ORDER BY ename .emp_query procedure.

.

LIBELLE VARCHAR2(100 BYTE). we can see how to handle a table that contains a nested table (collection). Here is the description of the table (ARTICLES) CREATE TABLE ARTICLES ( CODE VARCHAR2(20 BYTE).3.3 Block based on a relational table that contains a collection TEST_COLLECTION. PRIX NUMBER(8. CASES TAB_TYP_CASE ) NESTED TABLE CASES STORE AS CASES_NT RETURN AS VALUE.FMB In this dialog.2). QTETOT NUMBER(8.2.0). QTE NUMBER ) . There is no standard buit-in to base a block on a collection. TAB_TYP_CASE is a table of objects of type : TYP_CASE create or replace TYPE TYP_CASE AS OBJECT ( EMP VARCHAR2(10). but we will see how easy it is to work with this sort of object via the ON-xxx triggers.

TAB_TYP_CASE() -. Go_Block('CASES' ).EMP. Then after. Clear_Block . Indeed. Clear_Block . LC$Req ) .In this sample. cases. -. Set_Block_Property( 'CASES'. Populate the detail block (nested table) The detail block (CASES) is dynamically populated each time a master record change in a WhenNew-Record-Instance of the master block: Declare LC$Req Varchar2(256) . LIBELLE.QTETOT. Go_Block('ARTICLES') . Because it is not possible to create a new article with a NULL collection. Go_Block('ARTICLES') .CODE || ''') cases)' .Dynamic query of secondary block -LC$Req := '(SELECT cases. :ARTICLES.PRIX. Begin If :ARTICLES. PRIX. the first block (ARTICLES) displays the standard columns of the ARTICLE table and the second block (detail) displays the columns of its nested table.insert an empty collection ) .populate the block -Execute_Query . :ARTICLES. :ARTICLES.CODE Is not null Then -. QUERY_DATA_SOURCE_NAME. if we insert a NULL collection. CASES ) VALUES ( :ARTICLES. End if .we are doing an explicit insert because the new record --. Else Go_Block('CASES' ). End . QTETOT.LIBELLE. we have to handle the insertion into the ARTICLE table in a ON-INSERT trigger: --------------------------------------------------------------.cannot contain a NULL collection --------------------------------------------------------------INSERT INTO ARTICLES ( CODE.CODE. it is easy to manage the detail records with the ON-xxx triggers of the CASES block: ON-INSERT: . it will be no longer possible to insert anything in the nested table.QTE FROM TABLE ( SELECT cases FROM articles WHERE code = ''' || :ARTICLES.

ON-DELETE: -.CODE ) Values ( TYP_CASE( :CASES.QTE ) ). :CASES. . etc.-.Delete row in the collection -DELETE FROM TABLE ( SELECT cases FROM articles WHERE code = :ARTICLES.CODE ) cases WHERE cases.EMP .Insert the row in the collection -INSERT INTO TABLE ( SELECT cases FROM articles WHERE code = :ARTICLES.EMP.emp = :CASES.

(see the JANVIER.4 Block based on multiple data sources TEST_DATA_SOURCES.FMB I this sample dialog. we can see how to base a block on several tables that share an identical structure.3.2. FEVRIER and MARS tables created by the install.sql script) The list item is populated with the name of three tables that share the same structure: .

choix := :global. -.CHOIX is not null Then :global.change the Query Data Source -Set_Block_Property('TEST2'.choix . go_block('TEST2'). QUERY_DATA_SOURCE_NAME.Then. End if . :global. clear_form . .CHOIX ). execute_query.choix := :ctrl. the source table of the block is changed dynamically in the When-List-Changed trigger: If :CTRL.choix . :ctrl.

LIBELLE VARCHAR2 (100).FMB Let’s see how to manage an object table that contains a collection of references. This sample is based on the object table (ARTICLE_OBJ) that contains a collection of references: create or replace TYPE REF_TYP_EMP AS OBJECT ( ref_emp REF TYP_EMP ) create or replace TYPE TAB_REF_TYP_EMP AS TABLE OF REF_TYP_EMP create or replace TYPE TYP_ARTICLES AS OBJECT ( CODE VARCHAR2 (20).2). REMP TAB_REF_TYP_EMP -. QTETOT NUMBER (8).collection .5 Block based on an object table that contains a collection of references TEST_OBJETS.2. PRIX NUMBER (8.3.

CODE || ''')' . End if . . Go_Block('ARTICLES') . :ARTICLES. TAB_REF_TYP_EMP() ) ) .An ON-INSERT trigger to insert a new record with an empty collection: -------------------------------------------------------. -. Clear_Block .qte QTE FROM TABLE( SELECT REMP FROM articles_obj WHERE CODE = ''' || :ARTICLES.PRIX.A when-New-Record-Instance trigger on the master block to populate the detail block (the collection of references): Declare LC$Req Varchar2(256) .Dynamic query of secondary block -LC$Req := '(SELECT emp. Go_Block('ARTICLES') . QUERY_DATA_SOURCE_NAME. -. The tip is the same that the one used to manage the relational table with nested table: . LC$Req ) .CODE || ''') emp WHERE emp. Else Go_Block('CASES' ). End . Go_Block('CASES' ).record cannot contain a NULL collection -------------------------------------------------------INSERT INTO ARTICLES_OBJ VALUES ( TYP_ARTICLES ( :ARTICLES.change the Query Data Source Name -Set_Block_Property( 'CASES'.ref_emp. :ARTICLES.ref_emp. The collection of references is managed with the corresponding ON-xxx trigger of the detail block: ON-INSERT: -.populate the block -Execute_Query .LIBELLE. Begin If :ARTICLES.ref_emp.We are doing an implicit insert because the new --.QTETOT.) CREATE TABLE ARTICLES_OBJ OF TYP_ARTICLES NESTED TABLE REMP STORE AS REMP_NT RETURN AS VALUE. emp.CODE. Clear_Block .Insert a row (REF) in the collection -- .CODE Is not null Then -.art = ''' || :ARTICLES.emp EMP. :ARTICLES.

CODE || ''') VALUES ( REF_TYP_EMP ( (SELECT REF(a) FROM EMP_OBJ a WHERE a.CODE And emp.Declare LC$Req Varchar2(256) .CODE ) emp WHERE emp.ref_emp. ON-DELETE: -. .ART = ''' || :ARTICLES.emp = :CASES.ref_emp.EMP .art = :ARTICLES. Begin LC$Req := 'INSERT INTO TABLE ( SELECT remp FROM ARTICLES_OBJ WHERE code = ''' || :ARTICLES.CODE || ''' AND a.EMP = ''' || :CASES. End . Forms_Ddl( LC$Req ) .EMP || ''') ) )' .Delete the row (REF) of the collection -DELETE FROM TABLE ( SELECT remp FROM ARTICLES_OBJ WHERE code = :ARTICLES.

FMB Here is a description of the main items.4.2. Click everywhere on each item to see some information messages and some particular behaviours. .4 Items 2.1 Principal items TEST_ITEMS.

a) The first list item is populated with the RG_MOIS record group: -. 1 ) . POPULATE_LIST('BLOC2. CLEAR_LIST('BLOC2.2.Select the first value -:BLOC2.LISTE2'. POPULATE_LIST('BLOC2.List 1 -errcode := Populate_Group( 'RG_MOIS' ).Select the first value -:BLOC2.4.Update the days list -- .LISTE2 := Get_List_Element_Value('BLOC2. For each new list value.LISTE1'). BEGIN -. LC$Day Varchar2(20) .FMB Let’s study and handle the three sorts of list item and also the different ways to populate them.LISTE1'.LISTE1'. b) Then init the second list item -.LISTE2'. -. the three list items are synchronized. c) That finally init the third list item: PROCEDURE Init_Liste3 IS LC$D Varchar2(12) .Update the weeks list -errcode := Populate_Group( 'RG_SEMAINES' ).LISTE1 := Get_List_Element_Value('BLOC2. the corresponding value and label are displayed. Change the value of the first list and it will adapt the content of the second then the content of the third. In this sample.2 List items TEST_LISTES. CLEAR_LIST('BLOC2. 'RG_SEMAINES' ). 'RG_MOIS' ). 1 ) . -.LISTE2').

Clear_List( 'BLOC2. End loop . LC$Day ) .LISTE3'. END..LISTE3' ).LC$D := '01/01/2005' . LC$Day. 'DD/MM/YYYY' ) + (i + ((To_number(:BLOC2. For i IN 0. i + 1. . -.Select the first value -:BLOC2. 1 ) .LISTE2)1) * 7)). 'FMDay DD Month' ) Into LC$Day FROM dual . Exception When Others then Null . Add_List_Element('BLOC2.6 Loop SELECT to_char( To_date(LC$D.LISTE3'.LISTE3 := Get_List_Element_Value('BLOC2.

CONSTRAINT PHOTO_PK PRIMARY KEY (IDENTIFIANT) ENABLE ) .2. CREDIT VARCHAR2(50 BYTE) NOT NULL ENABLE. you can navigate on another canvas to display the detail of the picture: .0) NOT NULL ENABLE.4. NOM VARCHAR2(50 BYTE). attach and display images. You can build a photo album based on a one image’s column table. PHOTO BLOB NOT NULL ENABLE. By clicking on a picture. FORMAT VARCHAR2(50 BYTE) NOT NULL ENABLE.3 Image items ALBUM_PHOTO.FMB This dialog is the main part of the ensemble that allows to search. It shows two ways to search a filename on the local machine with and without Webutil. IDENTIFIANT NUMBER(5. LIEN VARCHAR2(100 BYTE). CREATE TABLE PHOTOS ( LEGENDE VARCHAR2(100 BYTE).

.

FMB The get_file_name sample dialog is only a “pure exercice of style” . . This sample is interesting to see how to use the HOST() and TEXT_IO() functions to get the list of the local machine drives and their content.CHARGE_PHOTO. because it is so easy to pickup a file with the File_Open_Dialog() Webutil function.

.CHARGE_PHOTO_WEBUTIL.FMB Another dialog to store the picture and its properties.

4 Java Bean component TEST_GRAPH.oracle.2. You can download the FormsGraph.4. This dialog use the Oracle FormsGraph Java Bean that is part of the Oracle Forms demos.zip .com/technology/sample_code/products/forms/files/formsgraph_patch2005.jar file on the OTN page http://www.FMB Here is a sample to demonstrate how to handle a bean area.

FMB Let’s see how to use the calculated items.5 Calculated items TESTS_CALCUL.2.4. The first calculated item use the Summary calculation mode: The third one use a Formula calculation mode .

.

5 Alerts TEST_ALERTES_MESSAGES. some of them can take from 1 up to 3 parmeters (%1. process ? (raise form_trigger_failure) ALERTE VARCHAR2(15). The main block is based on the MESSAGES table. %2 and %3). STOP VARCHAR2(1) DEFAULT 'N' NOT NULL ENABLE. To reduce the number of messages needed in the application. TEXTE VARCHAR2(256) NOT NULL ENABLE. CONSTRAINT MSG_PK PRIMARY KEY (CODE) ENABLE ) ----- unique identifiant text of the message title of the alert Shall we stop the -.FMB This dialog shows how to use the Alert boxes to build the messaging engine of your Forms application. CREATE TABLE MESSAGES ( CODE NUMBER(5.0) NOT NULL ENABLE. The message texts are read from the database then displayed via Alert boxes. A pipe (|) character allows to split the message on several lines.name of the alert box . TITRE VARCHAR2(100).2.

   AL_ERREUR wich is the simple “OK” alert box. AL_MSG_OUI_NON wich is a yes/no alert box (default yes) AL_MSG_NON_OUI wich is a yes/no alert box (default no) .This sample use the Affiche_Message() procedure of the TUTO_FORMS pl/sql library to display the messages. These messages can be displayed through the 3 alert boxes available in every dialog of this demo.

current record. Property classes and visual attributes are located in the OBJ_TUTO_FORMS. etc.).FMB Let’s see some ways to use the property classes and the visual attributes to colorize and highlight dynamically different objects of the form (alert. .6 Property classes and visual attributes TEST_CLASSES_PROP.2. item.olb object library.

zip file .zip file shipped with the article.FMB This dialog allows you to understand what trigger fire and in what order when you use the application. Before each particular action. 3. All the necessary objects are provided in the tutoforms10g. you can clear the list of triggers window.  Download the tutoforms10g. This window show you what trigger is firing in what order and from what block and what item.2. Installation steps This sample dialog need database objects to run. /scripts that contains the Sql script files to create the database objects.7 Forms internal triggering events TEST_CYCLES. This zip file contains 2 sub directories: /config that contains the configuration files.

bat file located in the same directory to compile all objects at once.g.jar.jar. you can start the demo by indicating the new [tutoforms10g] formsweb. Under the /tutoforms/ directory compile all the source modules You can use the compile_all.   Unzip the tutoforms10g. Create a new user in your database With Sql*plus or SqlDeveloper.sql script note : because this demo use the Webutil functions.%ORACLE_HOME%\forms\tut oforms\myIcons. lookAndFeel=Oracle colorScheme=blaf logo=no #don't forget to put your own database connexion userid=tutoforms10g/tutoforms10g@XE   Copy the /tutoforms/config/tutforms10g. e. run the /scripts/install.cfg section.. http://machine:8890/forms/frmservlet?config=tutoforms10g .cfg file  Then.%ORACLE_HOME%\forms\tutoforms\FormsGraph.jar.cfg at the end of your /forms/server/formsweb..jar. compile_all user/password@instance Edit the /tutoforms/config/tutforms10g.env file to indicate your own settings (in blue in this example) #oracle home adapt this value to your own setting ORACLE_HOME=D:\Dev10gR2 FORMS_PATH=%ORACLE_HOME%\forms\tutoforms ORACLE_PATH=%ORACLE_HOME%\forms\tutoforms FORMS_TRACE_PATH=%ORACLE_HOME%\forms\tutoforms CLASSPATH=D:\Dev10gR2\forms\java\frmwebutil.env to the /forms/server directory add the /tutoforms/config/ add_to_formsweb.cfg file to set your own database connect string (in blue in this example) .%ORACLE_HOME%\jlib\debugger .cfg    Edit the /tutoforms/config/ add_to_formsweb.zip file under your <DEVSUITE_HOME>/forms/ directory. # webutil config file path WEBUTIL_CONFIG=D:\Dev10gR2\forms\server\webutil. the Oracle user where you have created these objects must have the WEBUTIL_DB package compiled or a grant EXECUTE to this package if it is present in another schema.

90.344.

4/0.250*.8.

98.574/:.

14728.

108.

5*5.9.  5   .147287.

94324/0   .94324/0  %$%$*&      %097/430:80.:.472:...90/9028   09 8800494:8090....:.:..90/9028   %01789.:.  .90/902:8090$:22...:...7.

 .

907.30330414:74728 .9.4894859902088.-.0/.07...39.7.079 $% !'##  &%   %&  $.7070.80/4390$$$9.09098.:70  #%'##   3.7209078  .04380.39 %%'##   %&  90941902088.079-4  $%#%$*!!##      #%%$$$   .3-4.079-408  %470/:.3/ 550  .80903/85.943 842041902..0903:2-07412088..0 %%#'##   9904190.088 7.55.4848494:8090079-40894-:/902088.. 308   %02.801472*9707*1.01742:5 945.   0798  %$%*#%$*$$$   %8/.0894590 574..204190.8-.-0     &#   %&  :36:0/0391.943   %02088./174290/.08300/0/390.55.

0/:704190%&% * #$5.0*088.%88.250:809011.0 574.

8.079-408.079-4  *$* &* . 902088.08.07/...08.8908250  ..44198 /024   *##&#.794/85..-030.86-7.3-0/85.08  %0802088.0/974:90.

08.8.34.079-4 /01.:908  *$* * &.

34.079-4 /01.:934  .

894:80905745079.704..8808.  !745079.4470.079 902 .8:..8:..2..3/9 /3./11070394-0.8808.:7703970.3/.7  ..997-:90894.997-:908  %$%*$$$*!# !   09 88008420.997-:908.   !745079.3/90.90/390 *%&% * #$ 4-4-0.9-7.8808.8:....9841901472 .47/ 09.3/.

5.94389058  %88.943   014700..79.4.0398   %8/.0...:.439..79.250/.  472839073.55.94708  .9970781733..970730.3/1742.947/07034::8090 .74-0.9-4.9902      389../0/3909:9414728  5108550/990.-.98947:3  9030.947/07.0    %8510.3/3.99707170.7908941970783/4  %83/4844:.9.7.98.943 4:.388:-/70.484:94:3/0789.3/.088.3.70574.4300//.804-0.3/.

9.431:7.943108  .439.3890.4319..

-.9090/.9.3890$68./909:9414728  510 %$%*$  .70.9.804-0.75989.439.8.98    434.75910894.

 &35909:9414728  510:3/074:7'$&%* .

14728.

90.80   9$6 5:847$60.9.30:80734:7/.947   70./70.04507 7:390.-.

8.7598.

:8098/024:80900-:91:3..349078.02..   &3/0790.0 .70..090&%*5.019857080393.4250/47.90/90804-0.759 3490-0.7..0:8070704:.9438 90 7...389... 868.39 &%94985.0.982:89.

9:9414728.

4250*..:807.024/:08 4:..20/70.4250.90/3908.4-0.9084:7./70. -.98 .94794.9104.4250.943.0  0  .4250*.947.3:8090.

3.8847/389.0  /990.5.

9:9414728.

431..

1720-:9 ..:0944:74380993 #* 0.904:743809938 3-:03 980. #14728807..10943/.9:914728  03.070-:9 .7 #* -/0-:07 .9 &%* 0.438 ./. #   #$*!% #* 147289:9414728 #*!% #* 147289:9414728  #$*%#*!% #* 147289:9414728 $$!%0..250   47.0420.5998.7  0-:9.. #14728.7 #* 147289:941472847287.5 .7 #* 147289:9 4147282.431105..1  /990.

9:9414728.

.431.

.80.//*94*147280- .-.250    443/00 7.447$.4330.98973 3-:03980.0 .1 4434 /43 914709945:94:743/.433043 :807/9:9414728 .80 .-.020-.9..9.110948094:743/.

9:9414728   4590.

9:9414728.

431..

9:914728  03.9490.

14728.

947   .807.07/70.//90.

9:9414728.

.431.

1.//*94*147280- ..99003/41 4:7.

14728.

807.07.

9390309:9414728 (147280- .943    995...389.7990/024-3/.110   %03 4:.180.147280- .

.

30 .2..

14728.

4319:9414728      .09.172807.

    .

Sign up to vote on this title
UsefulNot useful