[Solved] Event Handler Problem

Jul 2, 2010 at 11:51 AM
Edited Jul 2, 2010 at 11:52 AM

Hi Arik,

I have a new problem with incorporating the Ribbon into my Eclipse Application. The language (Progress ABL) I program in the Eclipse IDE doesn't support events whose handler signature does not conform to .NET Framework convention, which is in this form: eventhandler(sender AS System.Object, e AS System.EventArgs ).

Is it possible to change the OnExecute event signature from (key AS RibbonLib.Interop.PropertyKeyRef, currentValue AS RibbonLib.Interop.PropVariantRef, commandExecutionProperties AS RibbonLib.Interop.IUISimplePropertySet) to the conventional way. i.e. (sender AS System.Object, e AS OnExecuteEventArgs), where OnExecuteEventArgs is derived from System.EventArgs and uses PropertyKeyRef, PropVariantRef and IUISimplePropertySet as data member?

Thanks

Ruan

Coordinator
Jul 2, 2010 at 12:56 PM
Well, theoretically it is possible. Unfortunately, this would be a breaking change for all current users of this library. What I can suggest is that you download the code and make your own version of library, one with the modified event as you suggested. Sorry I can't help you more but I'm afraid that doing a change like this will upset more than one user...
Jul 2, 2010 at 1:17 PM

Thanks for your reply Arik, that's okay, I will try if I can make it. I haven't programmed in C# for years, I am from .net framework 1.0 background :).

Are you able to give me some ideas in terms of what classes I will need to modify to accomodate that and other pitfall area?

Looking forward to your reply.

Regards
Ruan

Coordinator
Jul 2, 2010 at 1:33 PM
Just change the delegate type in these files: ExecuteEventsProvider and PreviewEventsProvider and change the Execute function in both files to raise the events with the new delegate type Other than that, just fix all the compilation errors you will get due to the change. The change is rather simple but as I've said it would break all the current clients..
Jul 2, 2010 at 1:45 PM

Oh, Thanks. Sounds like I don't have to create a new OnExecuteEventArgs class, Do I?

Will keep you updated how I go. Thank you so much for your support.

Cheers

Coordinator
Jul 2, 2010 at 1:54 PM

Well, I think you should create such a class.
Otherwise, how will you pass the parameters?

Good luck.

Jul 4, 2010 at 4:02 AM

Hi Arik,

I have accomplished my mission, my from can respond to the events now after I make the following modification to ExecuteEventsProvider and PreviewEventsProvider. Thank you very much indeed for your insights. ;-)

public delegate void OnExecuteEventHandler(object sender, OnExecuteEventArgs e);

public class OnExecuteEventArgs : System.EventArgs
    {
        private PropertyKeyRef _key; 
        private PropVariantRef _currentValue;
        private IUISimplePropertySet _commandExecutionProperties;

        public OnExecuteEventArgs(PropertyKeyRef key, PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)
        {
            _key = key;
            _currentValue = currentValue;
            _commandExecutionProperties = commandExecutionProperties;
        }

    }


public override HRESULT Execute(ExecutionVerb verb, PropertyKeyRef key, PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)
        {
            if (verb == ExecutionVerb.Execute)
            {
                if (OnExecute != null)
                {
                    _onExecuteEventArgs = new OnExecuteEventArgs(key, currentValue, commandExecutionProperties);
                    OnExecute(new object(), _onExecuteEventArgs);
                }
            }

            return HRESULT.S_OK;
        }
Jul 4, 2010 at 9:08 AM

Hi Arik,

Just a thought, is it possible to pass the actual instace of the object being clicked on the form to the OnExecute event? The above code only passes the generic object as the sender.

Thanks
Ruan

Coordinator
Jul 4, 2010 at 11:29 PM

Its possible, but you need to make additional modifications to the code to establish it.

Jul 5, 2010 at 7:39 AM
Edited Jul 5, 2010 at 7:45 AM

Can you shed some light on how to establish it please?

Thanks
Ruan

Coordinator
Jul 7, 2010 at 1:41 PM

You can add the to the constructor of both ExecuteEventProvider and PreviewEventsProvider a new parameter (object sender).

This parameter will be passed to the constructor by the ribbon element which created the events provided (e.g. RibbonButton)

The parameter will be used when raising the events.

 

Jul 10, 2010 at 3:04 AM

Hi Arik,

Thank you so much for your tips. I implemented it.

It's great, I can now have only one method in my from to handle events fired from different control and test the commandID to decide what specific code to run.

Cheers
Have a nice weekend.

Coordinator
Oct 9, 2010 at 1:57 AM

I've just replaced the event handling to be as discussed in this thread.
It will be available in the comming release (v2.5)