I have an object that handles the logging in of users. This object has a method called LoginPopUp(), which calls Login.show() to display the Login form/window.
The form/window is a seperate object. When a user enters their details and presses submit I want the form to pass data BACK to the calling object. The calling object (the object that handles loging in) will then validate the username and password. If the user is in the database it will close the window.
If the user is not in the database it will remain open and display “incorrect login”. So I need a way for the calling object to pass information back to the login window to tell it it’s failed.
Im a little confused on how to do this. Is this a case for callbacks and delegation? Whats the conventional solution to use in cases like this? As I’d imagine this happens a lot.
Comments appreciated.
You can do this with a delegate (aka callback). Have a delegate typed property of the login form that the caller can set. You can also do it with an event (which is also a delegate really) and have the login form expose an event that the caller can subscribe to before showing the form.
However, if the same action is always taken after login, then it might be more straightforward to do a direct call instead of using delegates.