Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button procedure

Status
Not open for further replies.

dps

Programmer
Feb 2, 2001
157
GB
Hello,

I am currently trying to turn around some existing code within Forms 5.0 using Forms 6i on a Ora817 db. I am trying to improve performance and also make the code more readable, minimal and efficient.

I currently have the following code as below.

Purpose of procedure: To enable or disable push buttons based on total number of records retrieved by form.

So if for eg. One rec retrieved then all buttons disabled. If multiple recs and current record position is first rec, then disbale button labelled First and prior and disable Next and Last button ...

Called by : w-b-p on each button (item level)
PROCEDURE SCROLL_CONTROL IS
BEGIN

/* NAME_IN function returns the contents of an indicated variable or item.
It is used to get te value of an item without referring to the item directly.*/

if name_in('SYSTEM.LAST_RECORD') = 'TRUE' and name_in ('SYSTEM.CURSOR_RECORD') = '1' THEN
set_item_property('button_palette.pb_first',enabled, property_off);
set_item_property('button_palette.pb_previous',enabled, property_off);
set_item_property('button_palette.pb_next',enabled, property_off);
set_item_property('button_palette.pb_last',enabled, property_off);
elsif name_in('SYSTEM.LAST_RECORD') = 'TRUE' THEN
set_item_property('button_palette.pb_first',enabled, property_on);
set_item_property('button_palette.pb_previous',enabled, property_on);
set_item_property('button_palette.pb_next',enabled, property_off);
set_item_property('button_palette.pb_last',enabled, property_off);
elsif name_in('SYSTEM.CURSOR_RECORD') = 'TRUE' THEN
set_item_property('button_palette.pb_first',enabled, property_off);
set_item_property('button_palette.pb_previous',enabled, property_off);
set_item_property('button_palette.pb_next',enabled, property_on);
set_item_property('button_palette.pb_last',enabled, property_on);
else
set_item_property('button_palette.pb_first',enabled, property_on);
set_item_property('button_palette.pb_previous',enabled, property_on);
set_item_property('button_palette.pb_next',enabled, property_on);
set_item_property('button_palette.pb_last',enabled, property_on);
end if;


END;

Any suggestions anyone?

I have looked at using name_in:)system.trigger_item) and get_item propoerty...but not quite getting it right.


Thanks in advance
 
Woops!!

The procedure scroll_control is actually called by W-N-R-Instance not W-B-P!!
 
SYSTEM.CURSOR_RECORD will return an integer not a pseudo-boolean, so your test

[tt]elsif name_in('SYSTEM.CURSOR_RECORD') = 'TRUE'[/tt]

will never return true.

Also, as an aside, when you ENABLE a button you also need to make it NAVIGABLE so that the user can tab to the button if necessary - BUT you cannot disable a button if it is the current item.
 
Since these buttons are dependent on record navigation, could you place the call to your procedure in the WHEN-NEW-RECORD-INSTANCE trigger instead? That way the buttons are set whenever the cursor rests on a row.

It has been a while since I worked with 5.0, but shouldn't it be PROPERTY_FALSE / PROPERTY_TRUE, not PROPERTY_OFF / PROPERTY_ON?

[sup]Beware of false knowledge; it is more dangerous than ignorance.[/sup][sup] ~George Bernard Shaw[/sup]
Consultant/Custom Forms & PL/SQL - Oracle 8.1.7 - Windows 2000
 
Sorry, just noticed your post about W-N-R. What symptoms are you getting?

[sup]Beware of false knowledge; it is more dangerous than ignorance.[/sup][sup] ~George Bernard Shaw[/sup]
Consultant/Custom Forms & PL/SQL - Oracle 8.1.7 - Windows 2000
 
LewisP and cooper - thanks for the response.

Actually typo - it should be elsif name_in('SYSTEM.CURSOR_RECORD') = 1

With respect to property ON (TRUE) - well it does seem to be doing what is intended.

But my question is how can I make this re-write this code in much lesser lines.

Thanks in advance

 
How about:
Code:
PROCEDURE SET_BUTTON
(P_BUTTON_NAME in varchar2, P_MODE in varchar2) IS
BEGIN
if   upper(P_MODE) = 'OFF' then
     set_item_property
       (P_BUTTON_NAME, enabled, property_false);
else
     set_item_property
       (P_BUTTON_NAME, enabled, property_true);
     set_item_property
       (P_BUTTON_NAME, navigable, property_true);
end if;
END;

PROCEDURE SCROLL_CONTROL IS
V_FIRST     varchar2(3) := 'OFF';
V_PREVIOUS  varchar2(3) := 'OFF';
V_NEXT      varchar2(3) := 'OFF';
V_LAST      varchar2(3) := 'OFF';
BEGIN
if    :SYSTEM.LAST_RECORD = 'TRUE' and 
      :SYSTEM.CURSOR_RECORD = '1' then
      null;
elsif :SYSTEM.LAST_RECORD = 'TRUE' then
      V_FIRST    := 'ON';
      V_PREVIOUS := 'ON';
elsif :SYSTEM.CURSOR_RECORD = '1' then
      V_NEXT     := 'ON';
      V_LAST     := 'ON';
else
      V_FIRST    := 'ON';
      V_PREVIOUS := 'ON';
      V_NEXT     := 'ON';
      V_LAST     := 'ON';
end if;
SET_BUTTON('button_palette.pb_first',V_FIRST);
SET_BUTTON('button_palette.pb_previous',V_PREVIOUS);
SET_BUTTON('button_palette.pb_next',V_NEXT);
SET_BUTTON('button_palette.pb_last',V_LAST);
END;

[sup]Beware of false knowledge; it is more dangerous than ignorance.[/sup][sup] ~George Bernard Shaw[/sup]
Consultant/Custom Forms & PL/SQL - Oracle 8.1.7 - Windows 2000
 
Thanks for that - it is certainly a different approach.

I take it the W-N-R-I would call the set button?

rgds,,
 
WHEN-NEW-RECORD-INSTANCE is the appropriate place if the buttons are controlled solely by row on which the cursor is placed. While the example provided may not be less lines of code, it does make reusable code units. The SET_BUTTON procedure can be used elsewhere if necessary. With the addition of comments it makes for maintainable code as well.
Code:
PROCEDURE SCROLL_CONTROL IS
/*============================*/
/* Set pallete scroll buttons */
/* Default is set button off  */
/*============================*/
V_FIRST     varchar2(3) := 'OFF';
V_PREVIOUS  varchar2(3) := 'OFF';
V_NEXT      varchar2(3) := 'OFF';
V_LAST      varchar2(3) := 'OFF';
BEGIN
/*======================================*/
/* If only one row, set all buttons off */
/*======================================*/
if    :SYSTEM.LAST_RECORD = 'TRUE' and 
      :SYSTEM.CURSOR_RECORD = '1' then
      null;
/*=====================================*/
/* If on last row, set FIRST & PREV on */
/*=====================================*/
elsif :SYSTEM.LAST_RECORD = 'TRUE' then
      V_FIRST    := 'ON';
      V_PREVIOUS := 'ON';
/*=====================================*/
/* If on first row, set NEXT & LAST on */
/*=====================================*/
elsif :SYSTEM.CURSOR_RECORD = '1' then
      V_NEXT     := 'ON';
      V_LAST     := 'ON';
/*===============================*/
/* otherwise, set all buttons on */
/*===============================*/
else
      V_FIRST    := 'ON';
      V_PREVIOUS := 'ON';
      V_NEXT     := 'ON';
      V_LAST     := 'ON';
end if;

/*=================================*/
/* Set buttons on or off as needed */
/*=================================*/
SET_BUTTON('button_palette.pb_first',V_FIRST);
SET_BUTTON('button_palette.pb_previous',V_PREVIOUS);
SET_BUTTON('button_palette.pb_next',V_NEXT);
SET_BUTTON('button_palette.pb_last',V_LAST);
END;

[sup]Beware of false knowledge; it is more dangerous than ignorance.[/sup][sup] ~George Bernard Shaw[/sup]
Consultant/Custom Forms & PL/SQL - Oracle 8.1.7 - Windows 2000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top