Articles home page

Oracle Forms "Multi-select records"

An Oracle Forms sample dialog that shows how to select/unselect records in a table-block.


 

 

What is it?

It allows the developer to let the end-user select/unselect multiple records in a table-block.
It does not require any extra item in the block.
It uses an in memory PL/SQL collection to store the table-block record status.
In addition, you can set the selected record attributes by using a Visual Attribute.

 

How it works

It is composed of:

  •  A Forms' PLL that hosts a package with procedures and functions required to handle the collections.
  • A (not mandatory) Visual Attribute to colorize the selected records.
  • Some Forms triggers to manage the feature.

The Forms PLL (multiselect.pll).

It contains a package (pkg_multiselect) to update the collection associated to the data table-block.

PACKAGE pkg_multiselect IS
  Type TAB_REC is table of pls_integer index by binary_integer;
  Type TAB_CHK is table of pls_integer index by binary_integer;
  Type REC_REC is record( name Varchar2(61), tab TAB_REC );
  Type REC_CHK is record( name Varchar2(61), tab TAB_CHK );
  Type TAB_REC_REC is table of REC_REC index by binary_integer;
  Type TAB_REC_CHK is table of REC_CHK index by binary_integer;
 
  procedure clear;
  procedure clear_all_blocks;
  function  get_state( numrec in pls_integer ) return pls_integer ;
  procedure set_state( numrec in pls_integer, value in pls_integer ) ;
  procedure change_state( numrec in pls_integer ) ;
  function  get_checked_list (blockname in varchar2 default null)  return TAB_CHK ;
  procedure set_visual_attribute_name ( vaname in varchar2);
  procedure set_select_visual_attributes
  (
     fontname   in varchar2 default null
    ,fontsize   in varchar2 default null
    ,fontweight in varchar2 default null
    ,background in varchar2 default null
    ,foreground in varchar2 default null
  );
END;

Every table-block has its own collection, that is a table of pls_integer, to store the record status; 1 for selected records, and 0 for unselected records.

CLEAR()
Used to clear (actualy delete) the collection associated to the data-block. It is called at query time, to remove previous record status.

CLEAR_ALL_BLOCKS()
Used to clear every collection associated to the current form. It is called at exit time, in the POST-FORM trigger.

CHANGE_STATE()
Used to toggle the double-clicked record state.

GET_CHECKED_LIST()
Returns a collection with the selected record numbers. This function has to be used to know, at any time, what record is selected, without having to loop through the physical records.

SET_VISUAL_ATTRIBUTE_NAME()
Used to set the Visual Attribute name used to colorize the selected record. The default Visual Attribute name is VA_SELECTED_RECORD, set in the package body.
If your form already contains a Visual Attribute with this exact name, you don't need to call this procedure.
If your form usually contains a Visual Attribute with another name, you can change it in the package body:

va_name varchar2(40) := 'VA_SELECTED_RECORD' ;

SET_SELECT_VISUAL_ATTRIBUTES()
Used to set the Visual Attribute properties, as needed.
If your form already holds a Visual Attribute with correct settings, you don't need to call this procedure.

If you don't need to use both SET_VISUAL_ATTRIBUTE_NAME() and SET_SELECT_VISUAL_ATTRIBUTES() procedures, because your Forms module already contains a correct Visual Attribute, so you don't need to keep the whole PRE-FORM trigger.

The Forms triggers

PRE-FORM
Contains calls to the SET_VISUAL_ATTRIBUTE_NAME() and SET_SELECT_VISUAL_ATTRIBUTES() procedures.
It is not required.

-------------------------------------------
--  not required if you already have a   --
--  VA_SELECTED_RECORD Visual Attribute  --
--  in your form                         --
-------------------------------------------
pkg_multiselect.set_visual_attribute_name ('VA_SELECTED_RECORD');
pkg_multiselect.set_select_visual_attributes
  (
    -- fontname   => 'courier'
    --,fontsize   => '1200'
     fontweight => FONT_BOLD
    ,background => 'r173g251b171'
    ,foreground => 'r0g0b240'
  );


POST-FORM
Contains a call to the CLEAR_ALL_BLOCKS() procedure to clear the collections before exiting the module.

-- clear the collection before exiting --
pkg_multiselect.clear_all_blocks;

 

KEY-EXEQRY
Clears the collection to handle new record status:

-- clear the collection --
pkg_multiselect.clear;
-- execute the query --
execute_query;


WHEN-MOUSE-DOUBLECLICK
Used to toggle the double-clicked record status:

pkg_multiselect.change_state(:system.cursor_record);

 

To know, at any time, the current record status, use the GET_STATE() function, that returns the current record status:

status := pkg_multiselect.get_state(get_block_property(:system.trigger_block, CURRENT_RECORD));

 

The Forms sample dialog

Download the multiselect.zip file.
Unzip the file.
Open and compile the multiselect.pll.
Open an run the selected_records.fmb module (Forms 10.1.2.0).

 

 

 

This Web page is created by Francois Degrelle