Home » D2k » Creating Timer in Oracle Forms / Forms 6i and Displaying a Clock

Creating Timer in Oracle Forms / Forms 6i and Displaying a Clock

Creating Timer in Oracle Forms / Forms 6i and Displaying a Clock

This is about timer in D2k

An external clock can be constructed using timers. Timers correspond to internal clocks, which have a specific time period. When the specified duration expires, the timer can either perform an action once and stop or repeat the action regularly every time the timer expires. Timer duration is always in milliseconds. Timers are created using the CREATE_TIMER built in Oracle Forms and require a WHEN-TIMER-EXPIRED trigger to be written at the form level. This trigger fires every time the timer expires.

Using REPEAT Timers

Let's create a display item, CURRENT_TIME, in the horizontal toolbar canvas CANVAS_TOOLBAR created earlier. This item shows the time in HH24:MI:SS format and updates itself every second (the timer duration).
In the WHEN-NEW-FORM-INSTANCE trigger, create a timer named CLOCK_TIMER, which iterates after every one second and populates the CURRENT_TIME item with the system date in HH24:MI:SS format. The code is as follows:
DECLARE

   timer_id TIMER;

   one_second NUMBER := 1000;

BEGIN

   timer_id := FIND_TIMER('CLOCK_TIMER');

   IF NOT ID_NULL(timer_id) THEN

     DELETE_TIMER(timer_id);

   ELSE

     timer_id := CREATE_TIMER('CLOCK_TIMER',one_second, REPEAT);

   END IF;

     SELECT  TO_CHAR(SYSDATE,'HH24:MI:SS')

     INTO   :toolbar.current_time

     FROM   DUAL;

   EXCEPTION WHEN OTHERS THEN

     MESSAGE(TO_CHAR(SQLCODE)||''||SQLERRM);

END;

Create a WHEN-TIMER-EXPIRED trigger as follows:
DECLARE

   timer_name VARCHAR2(30);

BEGIN

   timer_name := GET_APPLICATION_PROPERTY(TIMER_NAME);

   IF  timer_name = 'CLOCK_TIMER' THEN

      SELECT  TO_CHAR(SYSDATE,'HH24:MI:SS')

      INTO   :toolbar.current_time

      FROM   DUAL;

   END IF;

   EXCEPTION WHEN OTHERS THEN

      MESSAGE(TO_CHAR(SQLCODE)||''||SQLERRM);

END;

See Also: Create image presentation with Timer in Oracle Forms,

https://foxinfotech.in/2014/02/creating-stopping-restarting-deleting-timer-oracleforms.html

Creating, Stoping, Re-Starting timer in Oracle Forms

Tune Oracle Form's PLSQL Code with the help of timer


Creating Timer in Oracle D2k / Forms 6i and Displaying a Clock
Reviewed by Rishion Mar 17 2013
Rating: 4