Winsock object problem with WithEvents - vb6

I am developing a Standard EXE Project for sending mail.
I have a class module for sending email using winsock.
I have a withevents winsock variable set to the winsock control of a form.
The problem is that events are being catched in form's control event handler.
When i comment form's control event handling procedures and put a breakpoint in class module witheevents variable's event handler,i am unble to catch the events.
Please suggest a workaround.

If you really need to create a class (little c) that wraps constituent controls you create a UserControl, which can be invisible at runtime and have no UI interaction at all. Then, as the Winsock control's container, this UserControl will receive the events and you can handle them there.
I do this fairly often in order to create higher-level communication components, moving things like a message framing protocol inside. Then the container I put these UserControls onto only handles events raised when it has received complete messages for example. I've done the same thing to create an embeddable HTTP Server control, raising events back to the containing Form to process GET/POST requests with parameters and so on to provide a Web UI.
A Class (big C), Form, and UserControl are just three kinds of class (little c) you can create in VB6. "Class modules" really should have been called "UserClass" for clarity I suppose, in hindsight.

Related

Capturing and reacting to custom windows events in wxPython

I'm in the process of writing an app to interface with a service running on another machine. When I ask this service for some information, this service adds the requested information to a separate queue, and sends a windows message to the calling application (my application) indicating there is a message waiting in this separate queue which needs to be decoded.
The windows message this service sends is a custom message, defined in the service code as having some constant int value. I've found examples of creating custom events in wxpython, and using TryBefore() and TryAfter() to react to these events in specific ways, but I haven't found any way to associate this NewEvent() with an int value so I can identify it when it comes in, much less any way to determine what an int value of an incoming event is.
Has anyone done this before or know of any functions I'm not aware of? I'm using python 3.6 and wxpython 4.0.
Thanks for your help, everyone.
I think this is what you are looking for: https://wiki.wxpython.org/HookingTheWndProc
When you get the custom message from the hooked WndProc you can either react to it there, or you can turn it into a wx event and send it so it can be caught by binding an event handler like normal. The wx.lib.newevent module has some helpers for creating a custom event class and an event binder. Its use is demonstrated in some of the demo samples and library modules.

Need to remove the method that is added to Folder.Items.ItemAdd EventHandler?

I added a custom method to the Folder.Items.ItemAdd EventHandler during the Button click event in the Ribbon control of a Compose Email.
Now, Every time I click the button the EventHandler Item is getting added again and again.
So, because of it the custom method is calling n number of times for n number of clicks to the button.
I Need to check whether the custom method is already added to that Folder.Items.ItemAdd EventHandler
Please Help : #roopa, #Dmitry
I suppose this is a common programming question which is not related to Outlook or ribbon controls.
In case if you use C#:
How to correctly unregister an event handler
Removing event handlers
How to: Subscribe to and Unsubscribe from Events (C# Programming Guide)
Best practices for removing event handlers?
Visual Basic .Net:
AddHandler and RemoveHandler
VB.NET RemoveHandler & Anonymous Methods
Remove only one specific event handler in vb.net
explicit add/remove for Event in VB.net
Do you not store the Items object in a separate variable? Check if it is already set and do not set the event handler again.

Event Bus Vs HandlerManager in GWT?

When i working with one GWT project am using MVP pattern and HandlerManager for communicating on the application via Events. Now am implementing History Machanisam on my project.
They(GWT tearm) used Class EventBus for managing the events.
When read some blog i foud HandlerManger is used for Widgets and EventBus for other application wide communication.
But i feel both of them have same functionalities, then whats the purpose of this two implemetations, or whats the difference between them .
please help me
HandlerManager is the ancestor of the EventBus, which was extracted from (factored out of) it.
The main difference is that a HandlerManager has a source that it enforces on the events being dispatched to it, whereas EventBus can dispatch events with no source (fireEvent) or with a given dynamic source (fireEventFromSource). You can then attach handlers to the EventBus that will only be triggered for events from a given source.
Within widgets, you want to enforce that the event source is the widget. For a global application-wide event bus, you either want no source, or a source dynamically set for each event, as needed (RequestFactory uses it for its EntityProxyChange events so you can listen only to events related to a given kind of EntityProxy)
Note: the javadoc for HandlerManager discourages using it for an application-wide event bus.

Why are events defined as delegates

I have started working with ASP.NET controls and there appeared a question:
"why events in ASP controls are defined as delegates, and not as methods"?
Because an event must point to the function that it fires somehow and in C# this mechanism is achieved by delegates.
In response to the comment:
Then, why is such not a case with Java that uses only methods to fire
events?
Because Java uses the old traditional event pattern (like in C++). C# delegates are easier to use and also allow you to point to a static function rather than forcing the use of a class method.

Should events fire themselves?

I'm not a solid GUI programmer, so I'm trying to understand different event architectures. I'm developing a system (in GWT, but I'm not sure that matters) where we are introducing a few custom events. In general, is it good practice to create an event and have the event fire itself onto to the event bus?
Following some articles and tutorials online, we have our controller code actually firing the events, but then each controller has to duplicate the code to fire the custom event. It seems that if you just put a fire() method on the event itself you can avoid that duplication.
What are the pros/cons of doing this?
In order to have an event fire itself, you'd need to inject the EventBus instance into the event when you create it. This means your controller (the one newing up the event) would have:
new MyEvent(m_eventBus).fire();
If you rework the code like this:
MyEvent event = new MyEvent();
m_eventBus.fireEvent(event);
then you wouldn't have to put any logic or references to services inside your Event instance, where it's not really needed. If you're using GWT, the HandlerManager class already implements an event bus for you.

Resources