Sie sind auf Seite 1von 6

Chapter 7: FORM built-ins /* ** Built-in: GO_ITEM ** Example: navigate to an item which is on the canvas which the window displays.

*/ DECLARE itemname VARCHAR2(10); BEGIN itemname := ITEMID; Go_Item(itemname); END; /* CALL_FORM example * / DECLARE theformname VARCHAR2(20); BEGIN theformname := 'a:\chapter6\ch6customer.fmx'; /* ** Call ch6customer.fmx executable. The called form is modal with respect to the calling form ** Any windows that belong to the calling form are not usable until the called form is exited ** and control returns to the calling form. OPEN_FORM to invoke independent forms. */ CALL_FORM(theformname); END; /* GO_FORM example ** In a multiple-form application, navigates from the current form to the indicated target form ** Attempting to navigate to a form that has not yet been opened raises an error. */ PROCEDURE GO_FORM (form_name VARCHAR2); /* ** GO_BLOCK example ** Navigate to a block by name. Make sure to check that the Go_Block succeeds by checking */ ** FORM_SUCCESS */ BEGIN Go_Block('order_summary'); IF NOT FORM_SUCCESS THEN RAISE Form_Trigger_Failure; -- a predefined PL/SQL exception available only in form builder END IF; END; /* ** Built-in: GO_RECORD ** Example: Navigate to a record in the current block ** by record number. Also see FIRST_RECORD and ** LAST_RECORD built-ins. */ BEGIN Go_Record( :control.last_record_number ); END; /*

** Built-in: FIRST_RECORD ** Example: Have a button toggle between the first and last ** records in a block. ** Trigger: When-Button-Pressed */ BEGIN -- If we're not at the bottom, then go to the last record IF :System.Last_Record <> 'TRUE' THEN Last_Record; ELSE First_Record; END IF; END; /* ** Built-in: NEXT_RECORD ** Example: If the current item is the last item in the ** block, then skip to the next record instead of ** the default of going back to the first item in ** the same block ** Trigger: Key-Next-Item */ DECLARE cur_itm VARCHAR2(80) := :System.Cursor_Item; cur_blk VARCHAR2(80) := :System.Cursor_Block; lst_itm VARCHAR2(80); BEGIN lst_itm := cur_blk||'.'||Get_Block_Property(cur_blk,LAST_ITEM); IF cur_itm = lst_itm THEN Next_Record; ELSE Next_Item; END IF; END; /* ** Built-in: PREVIOUS_RECORD ** Example: If the current item is the first item in the ** block, then skip back to the previous record ** instead of the default of going to the last ** item in the same block ** Trigger: Key-Previous-Item */ DECLARE cur_itm VARCHAR2(80) := :System.Cursor_Item; cur_blk VARCHAR2(80) := :System.Cursor_Block; frs_itm VARCHAR2(80); BEGIN frs_itm := cur_blk||'.'||Get_Block_Property(cur_blk,FIRST_ITEM); IF cur_itm = frs_itm THEN Previous_Record; ELSE Previous_Item; END IF; END;

/* EXIT_FORM example */ BEGIN /* ** By default, Exit_Form asks to commit and performs a ** rollback to savepoint. If we've already posted, so we do ** not need to commit, and we don't want the posted changes ** to be rolled back. */ Exit_Form(NO_COMMIT, NO_ROLLBACK); END; /* ** Built-in: SHOW_ALERT,FIND_ALERT ** Example: Show a user-warning alert. If the user presses ** the OK button, then make REALLY sure they want ** to continue with another alert. */ DECLARE al_id Alert; al_button NUMBER; BEGIN al_id := Find_Alert('User_Warning'); IF Id_Null(al_id) THEN Message('User_Warning alert does not exist'); RAISE Form_Trigger_Failure; ELSE /* ** Show the warning alert */ al_button := Show_Alert(al_id); /* ** If user pressed OK (button 1) then bring up another ** alert to confirm -- button mappings are specified ** in the alert design */ IF al_button = ALERT_BUTTON1 THEN al_id := Find_Alert('Are_You_Sure'); IF Id_Null(al_id) THEN Message('The alert named: Are you sure? does not exist'); RAISE Form_Trigger_Failure; ELSE al_button := Show_Alert(al_id); IF al_button = ALERT_BUTTON2 THEN Erase_All_Employee_Records; END IF; END IF; END IF; END IF; END; /* ** Built-in: FIND_ITEM ** Example: Find an item's Id before setting several ** of its properties.

*/ PROCEDURE Hide_an_Item( item_name VARCHAR2, hide_it BOOLEAN) IS it_id Item; BEGIN it_id := Find_Item(item_name); IF Id_Null(it_id) THEN Message('No such item: '||item_name); RAISE Form_Trigger_Failure; ELSE IF hide_it THEN Set_Item_Property(it_id,VISIBLE,PROPERTY_FALSE); ELSE Set_Item_Property(it_id,VISIBLE,PROPERTY_TRUE); Set_Item_Property(it_id,ENABLED,PROPERTY_TRUE); Set_Item_Property(it_id,NAVIGABLE,PROPERTY_TRUE); END IF; END IF; END; /* ** Built-in: DBMS_ERROR_CODE,DBMS_ERROR_TEXT ** Example: Reword certain Form Builder error messages by ** evaluating the DBMS error code that caused them ** Trigger: On-Error */ DECLARE errcode NUMBER := ERROR_CODE; dbmserrcode NUMBER; dbmserrtext VARCHAR2(200); BEGIN IF errcode = 40508 THEN /* ** Form Builder had a problem INSERTing, so ** look at the Database error which ** caused the problem. */ dbmserrcode := DBMS_ERROR_CODE; dbmserrtext := DBMS_ERROR_TEXT; IF dbmserrcode = -1438 THEN /* ** ORA-01438 is "value too large for column" */ Message('Your number is too large. Try again.'); ELSIF dbmserrcode = -1400 THEN /* ** ORA-01400 is "Mandatory column is NULL" */ Message('You forgot to provide a value. Try again.'); ELSE /* ** Printout a generic message with the database ** error string in it. */ Message('Insert failed because of '||dbmserrtext); END IF;

END IF; END; /* ** Built-in: ERROR_CODE,ERROR_TEXT,ERROR_TYPE ** Example: Reword certain FRM error messages by checking ** the Error_Code in an ON-ERROR trigger ** Trigger: On-Error */ DECLARE errnum NUMBER := ERROR_CODE; errtxt VARCHAR2(80) := ERROR_TEXT; errtyp VARCHAR2(3) := ERROR_TYPE; BEGIN IF errnum = 40107 THEN Message('You cannot navigate to this non-displayed item... Try again.'); ELSIF errnum = 40109 THEN Message('If you want to leave this block, you must first cancel Enter Query mode.'); ELSE /* ** Print the Normal Message that would have appeared ** ** Default Error Message Text Goes Here */ Message(errtyp||'-'||TO_CHAR(errnum)||': '||errtxt); RAISE Form_Trigger_Failure; END IF; END; /* ** Built-in: MESSAGE_CODE,MESSAGE_TEXT,MESSAGE_TYPE ** Example: Reword certain FRM message messages by checking ** the Message_Code in an ON-MESSAGE trigger ** Trigger: On-Message */ DECLARE msgnum NUMBER := MESSAGE_CODE; msgtxt VARCHAR2(80) := MESSAGE_TEXT; msgtyp VARCHAR2(3) := MESSAGE_TYPE; BEGIN IF msgnum = 40400 THEN Message('Your changes have been made permanent.'); ELSIF msgnum = 40401 THEN Message('You have no unsaved changes outstanding.'); ELSE /* ** Print the Normal Message that would have appeared ** ** FRM-12345: Message Text Goes Here */ Message(msgtyp||'-'||TO_CHAR(msgnum)||': '||msgtxt); END IF; END;

/* ** To reference the MDI application window in a call to SET_WINDOW_PROPERTY, use the constant ** FORMS_MDI_WINDOW: */ Set_Window_Property(FORMS_MDI_WINDOW, POSITION, 5,10) Set_Window_Property(FORMS_MDI_WINDOW, WINDOW_STATE, MINIMIZE)

Das könnte Ihnen auch gefallen