Tuesday, 14 October 2014

How to create an ALERT window in Oracle FORMS.

It is not always useful and unconventional to use message utility in Oracle Forms. Message utility only display message on left corner of status bar. And sometimes we use a trick to display alert window in Forms by invoking message procedure twice. But that is not a solution. So we should learn how to create an alert window and I am sure after going through this lesson you can easily create one alert window in your application.





As above picture shows, open object browser and double click on Alerts Node or select Alerts node and click on + button on the toolbar on the left pane.


     Open the property pallet of alert item, and set the Alert style, Button label, I have taken 2 buttons,
     as you can see, I have set OK and Cancel of Button 1 Label  and Button 2 Label ad set Default
     Alert button as Button 2.


    Create a program unit named MSG (I assume you know how to create program unit) . I will give
    the code for the MSG program, MSG program will actually will call the alert window.

    PROCEDURE msg(msgstr varchar2) IS
    alrt_id ALERT:= find_alert('ALRT');  -- ALRT is the name of the Alert item you have named.
    ret number;

   BEGIN
        if not id_null(alrt_id) then
           set_alert_property(alrt_id,title,msgstr);  -- Message title for the alert window.
           set_alert_property(alrt_id,message_text,msgstr);  -- Message set for the alert window.
           ret:= show_alert(alrt_id);
           if ret = ALERT_BUTTON1 then
                  message('Pressed Ok');
           elseif ret = ALERT_BUTTON2 then
               exit_form;
           end if;
       end if;
   END;

Now all you need  to do is create a button in your form window and invoke the MSG procedure.


No comments: