cancel
Showing results for 
Search instead for 
Did you mean: 

Event trapping ....

Former Member
0 Kudos

Bit of a long one this , so hope you can bare with me ...

I have an addon which consists of a number of screens fired up from menus .. One of the screens is a UDO which , when i press cancel key , takes me back to main menu and i can select it again .. Another of the screens has just a matrix and a couple of buttons on it - one of which is a cancel button .. Now when i press the cancel button it takes me back to the main menu BUT it wont let me select and other menu items associated with my addon - standard SAP options are fine. Nothing happens on selection .. I looked at the events using event logger and I can see the Menu Event being selected but the screens never open .. I used B1DE to generate the listeners and in the form close button listener I have ..



  [B1Listener(BoEventTypes.et_CLICK, false)]

        public virtual void OnAfterClick(ItemEvent pVal) {
            bool ActionSuccess = pVal.ActionSuccess;
            Form form = B1Connections.theAppl.Forms.Item(pVal.FormUID);
            Item item = form.Items.Item("btCancel");
            Button button = ((Button)(item.Specific));
            // ADD YOUR ACTION CODE HERE ...

            form.Close();
        }

I suspected that it maybe something to do with event filtering in my addon so I added following code at the top

of the constructor to see if it would work ..



    // ADD YOUR INITIALIZATION CODE HERE	...

            EventFilters filters = B1Connections.theAppl.GetFilter();

            //  Create list of events/types we are interested in  .. 

            EventFilter filter = filters.Add(BoEventTypes.et_KEY_DOWN);
            filter.AddEx("MyScreen");

            filter = filters.Add(BoEventTypes.et_PICKER_CLICKED);
            filter.AddEx("MyScreen");

            // filter = filters.Add(BoEventTypes.et_FORM_CLOSE);
            // filter.AddEx("MyScreen");

            B1Connections.theAppl.ItemEvent += new _IApplicationEvents_ItemEventEventHandler(theAppl_ItemEventHandler);
            
            B1Connections.theAppl.SetFilter(filters);

Note the comments around the FORM-CLOSE filter .. When I remove these and run addon in debug I get an error when connecting to SAP saying "Connection Failed : An attempt was made to reference a token which does not exist" .. If I leave the comments then the addon starts up BUT i have the previously mentioned error with selecting options from menus .. I thought that the FORM_CLOSE event would be handled by the same handler as I use for KEY_DOWN / PICKER_CLICKED - they seem to work fine if FORM_CLOSE commented out .. Also If I use filters in this way is it then my responsibility to explicitely define every event on every screen in my addon in which i am interested ? Finally is there any other way of registering a listener for a keypress on a form in B1DE ? I can't find anywhere where this event is exposed ..

I am on S2007 A P/L 15 .. Also I have stopped / restarted SAP and cleared temp directory and it made no difference .. I'm still pretty new to SAP but i'm finding developing for it a little frustrating .. Can anyone help ?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Rob,

it may sound weird but I wonder why you need to handle click of cancel button at all. I mean, if in screen painter or through code, the button is created with unique id 2, it will close the form itself on clicking. and you need not write form.close(). unless you want to wipe out some variables on the closing of the form.

Regards,

Binita Joshi

Former Member
0 Kudos

The cancel button with a UDO is created with an id of 2 , but not a standard form - it's created with whatever you give it .. I can change them and restructure my code but i suppose my real question is why do i have to ? What is wrong with the actual code ? As i say i'm fairly new at SAP but i just seem to find little gotchas all over ! Maybe it's just me ..

Former Member
0 Kudos

Rob,

you do have a valid point but my question is, if the cancel button on all the user defined forms are created with the unique id "2", then why do you need to handle its click? it will anyway behave the standard way.

I want to know , if you comment the code (both the snippets you posted) and click cancel, what happens?

Binita

Former Member
0 Kudos

If i change the id to 2 and remove the handler it works .. So , it will do .. I will move my closing code to a different event handler - the ones above where skeletons i'd removed code from ..