AddHandler Question (MBS Plugin)

I am attempting to make a self-contained search field using the MBS controls.

In the examples it shows that there are two classes used, CocoaControlMBS and a sub-classed CustomNSSearchFieldMBS. The sub-classed class uses its Action method to communicate with the application.

What I want to do is make the Action event available to the application from the CocoaControlMBS class. What I have done is created a new Class which inherits from CocoaControlMBS. In the new class’s GetView event I have placed the following code:

[code] intFld = new CustomNSSearchFieldMBS(0,0,me.Width,me.Height)

’ Various intFld settings made here

AddHandler intFld.Action, AddressOf DoIt

Return intFld
[/code]
I have added a new method to my new Class called ‘DoIt(sender As CustomNSSearchFieldMBS)’. Inside ‘DoIt’ is the following code:

RaiseEvent Action(sender.StringValue)
I have added an Event Definition of ‘Action’ to the Class.

I would have thought that the internal CustomNSSearchFieldMBS would now send its Action event to My class’s DoIt which, in turn, will send it to the Action event definition but nothing happens in a compiled test.

Any thoughts, please?

If the action event is not connected in the constructor, it will not be installed at all. This is an internal optimization to avoid having code active which is never used.

But I can add a method EnableEvents there to connect the events after you used AddHandler.

So, if I create the intFld variable in the Constructor of my new Class I can add the AddHandler there and just return intFld in the GetView?

And, yes please, to the EnableEvents method!

I think you would need to call the addHandler before the Super.Constructor. Than it may work.

I’ll try that out today when I get to my desk. I will post again shortly.

Thanks, Christian.

I tried it with the intFld creation both before and after Super.Constructor with no difference.

I guess I will wait for the EnableEvents method.