Home » Developer & Programmer » Forms » Dynamic Item Properties Control and Apply (Forms [32 Bit] Version 10.1.2.0.2 (Production), Windows 7)
Dynamic Item Properties Control and Apply [message #637842] Wed, 27 May 2015 04:38 Go to next message
myclassic
Messages: 136
Registered: December 2006
Location: Pakistan
Senior Member
I want to apply different properties of an item as per user configuration. e.g. one user want to make an item enabled and other want it disabled.

So to achieve this I have created a table
USERID VARCHAR2(100) not null,
FORM_NAME VARCHAR2(35) not null,
BLOCK_NAME VARCHAR2(35) not null,
ITEM_NAME VARCHAR2(35) not null,
PROPERTY_NAME VARCHAR2(100) not null,
PROPERTY_VALUE VARCHAR2(100) not null

Data is like
WARD_USER1 BMS260 CTRL BTNTRANSFER 79 5
WARD_USER1 BMS260 CTRL BTNREPRINTBILL 79 4

for enabled/disabled the property value is 79 and for true / false, it is 4/5.

can any one help me to know the values of Required, Update allowed, Insert allowed etc
Thanks
Re: Dynamic Item Properties Control and Apply [message #637844 is a reply to message #637842] Wed, 27 May 2015 06:06 Go to previous messageGo to next message
Littlefoot
Messages: 21806
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I think I understand what you'd like to do, but - I'm afraid you can't do it that way (hopefully, someone else will know better).

This is a piece of code you'd want to utilize:
begin
  for cur_r in (select item_name, 
                       property_name, 
	               property_value
	        from your_table
                where ...
	       )
  loop
    set_item_property(cur_r.item_name, cur_r.property_name, cur_r.property_value);
  end loop;
end;

Once you run such a code, you'll get "Too many declarations of SET_ITEM_PROPERTY match this call". The main culprit is PROPERTY_NAME - you can't pass it that way.

set_item_property(cur_r.item_name, ENABLED, cur_r.property_value)
compiles, but you'll hit "FRM-41046: invalid parameter used for SET_ITEM_PROPERTY" error once you run the form.

It appears that some kind of dynamic code would be useful, but - I don't know it ...

Therefore, I'm afraid that you'll have to do it in an ugly way, such as
if userid in (1, 5, 200) then
   set_item_property('dept.dname', enabled, property_false);
   set_item_property('emp.sal'   , enabled, property_false);
   ...
elsif userid in (4, 7, 205, 1034) then
   set_item_property 
   ...
elsif 
   ...
end if


Once again: I hope that someone else did it the smart way and that he/she will see this question and provide useful suggestion, because mine is all but smart.
Re: Dynamic Item Properties Control and Apply [message #638056 is a reply to message #637844] Mon, 01 June 2015 17:07 Go to previous messageGo to next message
CraigB
Messages: 386
Registered: August 2014
Location: Utah, USA
Senior Member
It is not a good idea to use the numeric value of Forms Property CONSTANTS. There are intentional names for these for a reason. A better option would be to create a Forms Program Unit procedure that Enables or Disables an item and simply pass the name of the item. For example:
/* sample Forms Program Unit */
/* Code not tested... */
PROCEDURE enable_item (p_block_item_name VARCHAR2, p_status VARCHAR2 DEFAULT 'TRUE') IS
BEGIN
  IF ( p_status = 'TRUE' ) THEN 
    Set_Item_Property(p_block_item_name,ENABLED,PROPERTY_TRUE);
  ELSE
    Set_Item_Property(p_block_item_name,ENABLED,PROPERTY_FALSE);
  END IF;
END;

Then call this procedure instead of the built-in. To take this a step further, to handle the other properties you want to modify, you could create a Program Unit package that has a single public procedure that simply looks at the parameters passed and calls the appropriate private package procedure to effect the desired property. You would need to modify your table design to store the "Text" name for the property rather than the numeric value of the property.

For example,
/* Sample Package Specification - untested... */
PACKAGE change_item IS
  procedure change_property (p_block_name VARCHAR2, p_item_name VARCHAR2, p_property VARCHAR2, p_status VARCHAR2 DEFAULT 'TRUE');
END change_item;

/* Sample Package Body - untested... */
PACKAGE BODY change_item IS
  /* Private procedures... */
  Item_Enabled(p_blk_item_name VARCHAR2, p_status VARCHAR2) IS
  BEGIN
    IF ( p_status = 'TRUE' ) THEN 
      Set_Item_Property(p_blk_item_name,ENABLED,PROPERTY_TRUE);
      -- Remember, if an Item was disabled, there are additional properties 
      -- that are set to FALSE also... (NAVIGABLE, UPDATE_ALLOWED, UPDATE_NULL) 
      -- so you have to set them TRUE when you enable the item.
      Set_Item_Property(p_blk_item_name,NAVIGABLE,PROPERTY_TRUE);
      Set_Item_Property(p_blk_item_name,UPDATE_ALLOWED,PROPERTY_TRUE);
      Set_Item_Property(p_blk_item_name,UPDATE_NULL,PROPERTY_TRUE);
    ELSE
      Set_Item_Property(p_blk_item_name,ENABLED,PROPERTY_FALSE);
    END IF;
  END Item_Enabled;

  PROCEDURE Item_Required (p_bkl_item_name VARCHAR2, p_status VARCHAR2) IS
  BEGIN
    IF ( p_status = 'TRUE' ) THEN 
      Set_Item_Property(p_blk_item_name,REQUIRED,PROPERTY_TRUE);
    ELSE
      Set_Item_Property(p_blk_item_name,REQUIRED,PROPERTY_FALSE);
    END IF;
  END;

  PROCEDURE Change_Property(p_block_name VARCHAR2, p_item_name VARCHAR2, p_property VARCHAR2, p_status VARCHAR2 DEFAULT 'TRUE') IS
  BEGIN
     IF ( p_property = 'ENABLED' ) THEN 
        Item_Enabled(p_block_name||'.'||p_item_name,p_status);
     ELSIF ( p_property = 'REQUIRED' ) THEN 
        Item_Required(p_block_name||'.'||p_item_name,p_status);
     ELSIF ( .... The rest of the properties here...
     
     END IF;
  END Change_Property;
END Change_Item;

Were I writing this, I would use the package. There is a little bit of work up front, but it gives you the functionality you are looking for. KEEP IN MIND if you are altering the properties of the item you are currently on (eg: where the navigation cursor is), then you will get an error unless you navigate away from the item you are changing.

Hope this helps,
Craig...
Re: Dynamic Item Properties Control and Apply [message #638091 is a reply to message #638056] Tue, 02 June 2015 03:33 Go to previous message
cookiemonster
Messages: 13917
Registered: September 2008
Location: Rainy Manchester
Senior Member
CraigB wrote on Mon, 01 June 2015 23:07
KEEP IN MIND if you are altering the properties of the item you are currently on (eg: where the navigation cursor is), then you will get an error unless you navigate away from the item you are changing.


That really only applies when setting the enabled and visible properties.
Previous Topic: Make a form searchable at the line level
Next Topic: Create Current Record Indicator in Display Item
Goto Forum:
  


Current Time: Thu Mar 28 13:29:45 CDT 2024