delegates

NSTextDidEndEditingNotification causing error

Hi. I'm have a TextViewCell with a text field that that I'm using in a tableview. I need the current view controller to be the delegate. Nothing worked and in my searches I found the code below, which I implemented in my initWithNib method: NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selec...

Can I get some advice on JavaScript delegates?

I'm rusty with delegates and closures in JavaScript, and think I came across a situation where I'd like to try to use one or both. I have a web app that behaves a lot like a forms app, with fields hitting a server to change data on every onBlur or onChange (depending on the form element). I use ASP.NET 3.5's Web Services and jQuery to d...

Can Delegate.DynamicInvoke be avoided in this generic code?

This question is partly about delegates, and partly about generics. Given the simplified code: internal sealed class TypeDispatchProcessor { private readonly Dictionary<Type, Delegate> _actionByType = new Dictionary<Type, Delegate>(); public void RegisterProcedure<T>(Action<T> action) { _actionByType[typeo...

C# delegate definition - anonymous methods vs. formally defined methods

When should anonymous methods be used when defining a delegate and when should formally defined methods be used when defining a delegate ? ...

Best aproach to java like adapters event-handling in C++

I'm doing some research in how to implement a event-handling scheme in C++ that can be easyest as its to implements an adpter to a class in java. The problem is that with the approach shown below, I will need to have all adapters already implemented with its function overriding in the devived class (because the linker needs it). On the o...

What would I lose by abandoning the standard EventHandler pattern in .NET?

There's a standard pattern for events in .NET - they use a delegate type that takes a plain object called sender and then the actual "payload" in a second parameter, which should be derived from EventArgs. The rationale for the second parameter being derived from EventArgs seems pretty clear (see the .NET Framework Standard Library Anno...

Event and delegate contravariance in .NET 4.0 and C# 4.0

While investigating this question I got curious about how the new covariance/contravariance features in C# 4.0 will affect it. In Beta 1, C# seems to disagree with the CLR. Back in C# 3.0, if you had: public event EventHandler<ClickEventArgs> Click; ... and then elsewhere you had: button.Click += new EventHandler<EventArgs>(button_C...

In what way do you use delegates and/or events other than for the UI?

I am curious as to how other developers use delegates and/or events other than for responding to UI events? I, personally, don't use them for anything other than responding to UI events but I have a strong feeling that I am missing out on the power of delegates and events. So I pose this question to the SO community so that I may get s...

Weird error for UIActionSheets when compiling against iPhone 3.0 OS

Hi all, I recently started compiling my iPhone application against the 3.0 OS. The app worked fine when compiled against 2.2.1 however, compiling against 3.0 yields the following warning: warning: type 'id ' does not conform to the 'UIActionSheetDelegate' protocol This occurs on the 2nd line of the following code snippet whi...

How do I shared an object between UIViewControllers on iPhone?

My application is a tab bar application, with a separate view controller for each tab. I have an object in my first view controller (A) which contains all my stored application data (Please ignore NSUserDefaults for this) which needs to be accessed by the second view controller (B) when I press a button on it. How can I achieve this cou...

Builds a Delegate from MethodInfo ?

After googling and landing on SO and having read this other question Is it possible to build a correct Delegate from a MethodInfo if you didn't know the number or types of parameters at compile time? More on this: can this be done elegantly without the use of Reflection.Emit or type builders? This is sorta a bummer for me because ...

AsyncWaitHandle to terminate 3rd party API properly implemented?

Hi, "session.identify" is a third party COM API that I call and have no access to. It performs a server query that, somehow, locks up occasionally (and thus halts the main program which is waiting for the result). My attempt was to wrap it in an AsyncDelegate so I would be able to give it a timeout and after expiration of the timeout ...

Could we save delegates in a file (C#)

I have a class which has a delegate member. I can set the delegate for each instantiated object of that class but has not found any way to save that object yet ...

C# events of a non-delegate type

I've implemented a class that looks like this interface: [ImmutableObject(true)] public interface ICustomEvent { void Invoke(object sender, EventArgs e); ICustomEvent Combine(EventHandler handler); ICustomEvent Remove(EventHandler handler); ICustomEvent Combine(ICustomEvent other); ICustomEvent Remove(ICustomEvent ...

How can I execute code when value of a variable changes in C#?

I want to toggle a button's visibility in when value of a particular variable changes. Is there a way to attach some kind of delegate to a variable which executes automatically when value changes? ...

Are .NET delegates used for events?

I'm little confused, I know that delegates are like function pointers, and they are used to pass a function as a parameter into a method. How does that fit into the event model? Calling: myButton.OnClick += new .....(); Is that internally just passing the method/function as a parameter when the event occurs and all the subscribers a...

VB.NET API Delegates , Events ??? HELP Please

Hi All, I am stuck trying to work out Events and Delegates. I am trying to hook up to an external API which return events when certain events occur. The original code was written in C#, and I am trying to do this in VB.net Here is a short comment from the API programmers. "After that, client app should need to wait for one of events: ...

inline generic delegate (not the normal Action<T> Func<T, TResult>)

Is it possible to write an inline generic method? For example, how can I translate the below method into an inline delegate. public TUser Current<TUser>() where TUser : User { return getCurrentUser() as TUser; } Even just being able to call Func<User> userFunc = new Func<User>(Current<User>); would be useful. ...

How to create asynchronous method in c#

I have simple method in my C# app, it picks file from FTP server and parses it and stores the data in DB. I want it to be asynchronous, so that user perform other operations on App, once parsing is done he has to get message stating "Parsing is done". I know it can achieved through asynchronous method call but I dont know how to do that...

Prompting and Delegate question

I have a class that needs to ask the user a question and wait for the users response to determine the next action. What would be the best way to do this? Using a delegate? How? I have a UITextField and a UITextField in the class. Thanks ...