delegates

How to get touch coordinates upon SELECTING a custom UITableViewCell?

When I touch (Touch Up) a UITableViewCell my ViewController's UITableViewDelegate method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath is called. I need to get the x-coordinate of the Touch-Point at this time as well so that I can know what portion of the Cell was touched (non-accessory items...

How to subscribe to an event dynamically using anonymous methods?

I'm creating a number of UserControls dynamically using LoadControl(String) and want to subscribe to an event of each of them. All my controls inherits a common Interface that require an implementation of a common Event: public interface IObjectProcessor { event EventHandler<ObjectProcessedEventArgs> ObjectProcessed; } So I do next ...

Anonymous methods, scope, and serialization.

Let's say I have the following code: public class Foo { private int x; private int y; public Bar CreateBar() { return new Bar(x, () => y); } } [Serializable] public class Bar { private int a; private Func<int> b; public Bar(int a, Func<int> b) { this.a = a; this.b = b; }...

Accessing instance variables from UITableView delegate methods

Question: I'm trying to access a variable from the UITableView tableView:didSelectRowAtIndexPath: delegate method. The variable can be accessed from the data source methods, but when I try to access it from delegate methods such as this one, the app crashes. I declare the variable in my .h file, and initialise it in .m file in the appl...

EventHandlers and C# Classes destructor/Dispose

Hi, I'm a bit confused about C# Classes and their deconstructor. I have to consume a few event handlers in a class instance I'm getting in the contructor: public Foo(IFooHandler handler) { handler.Load += Load; handler.Close += Close; } Now my question is that I need unsubscribe to that event when the Foo class is destr...

How can I refactor these functions to foster code-reuse?

I wrote these helper functions a few weeks ago and I feel like I'm not taking advantage of some C# language features that would keep me from writing these same loops again for other similar helpers. Can anyone suggest what I'm missing? public static IList<string> GetListOfLinesThatContainTextFromList( Stream aTextStream, IList<...

How can I call a method on a form from a method called from an external class from a backgroundWorker?

How can I call a method on a form from a method called from an external class from a backgroundWorker? I believe that delegates are somehow the answer to this question, but after spending time reading, I still am confused by this problem. This is in Visual Studio 2008, the backgroundWorker is run from the form and calls ExternalClass.Me...

Best practices: When should I use a delegate in .NET?

Possible Duplicates: Delegate Usage : Business Applications Where do I use delegates? Hi, I'm new to the concept of a delegate in .NET - I haven't really used them yet and think they are probably there for a good reason - when should I be using a delegate? Examples are very welcome. ...

How to do a nonblocking update to a datagridview in c#.

I understand how to use delegates to update controls on the main control thread, works like a charm. My problem here is if I'm adding a large dataset (say 2000 items) to a bound datagridview it takes 5-8 seconds for the grid to populate and during that 5-8 seconds the whole gui is locked. How can I update the datagridview such that it ...

UITextView delegate not getting all method calls

I have a UIViewController that implements UITextViewDelegate and is connected as the delegate to my UITextView. Whenever the text view is tapped, I get a call to: - (void)textFieldDidBeginEditing:(UITextField *)sender and whenever the contents of the view change (keyboard, programmatic modification), I get calls to: - (void)textVi...

How to determine if an event is complete using a 3rd Party API - C#?

I am currently working with a third party ActiveX control where I need to detect when an event I called from the API has completed. Looking at the ActiveX control in VS 2008 Object browser, I call public virtual bool MyMethod() and there is an event public virtual event IActiveXObject_MyMethodEventHandler SettleComplete. There is als...

Removing event handlers

Is this: Button.Click -= new EventHandler(Button_Click); the same as this: Button.Click -= Button_Click; I ask because to me it seems that the former is removing a new reference to a method, and the latter one is removing a method itself. But then again, maybe the new EventHandler part is implicit in the += or -= overload in case t...

C# Making a delegate available to a class

I would like to make a delegate available to an entire class. The point of this is to allow a called method from an external class' backgroundWorker to continually report back through all of it's methods (ExternalClass.Run(); calls ExternalClass.Method2(); ExternalClass.Method3(); etc and they all need to send several progress reports. I...

Delegate.CreateDelegate without prototype.

Right now, I have to do this private delegate void set(int obj); //declare the prototype ... Delegate delegate1 = Delegate.CreateDelegate(typeof(set), new testObject(), props[0].GetSetMethod()); ((set)delegate1)(1); Is there a way to CreateDelegate without that prototype and call it with any parameter? GetSetMethod() returns a very ...

Refactor methods invoking delgates with different parameter signatures

Is there a pattern that I could apply to refactor this code? The only difference between the two methods is that that one method takes an extra parameter and passes it to the delegate? I found out that delegates cannot take overloaded method signatures. How could I add one more level of indirection? :) public static void ProcessFolder(...

Type id <Protocol1> does not conform to id <Protocol2> -- but it does!

Alright, I have two protocols in the same header file, let's call them Protocol1 and Protocol2. I have a main app controller that conforms to both protocols, and an NSWindowController subclass that has the following member: id <Protocol1, Protocol2> delegate; I'm getting a warning at the end of my NSWindowController subclass implemen...

iPhone dev - delegates, notifications, unsubscribe before deallocated?

In my question about using a delegate or a UIControl Event, this was in Kendall Helmstetter Geln's answer: Both are about an equal load to work with - with a delegate you have to set yourself and then remember to unset yourself before you are deallocated. You have to do the same thing with notifications, remember to start listening a...

C# - Win Forms - Event flow Cycle

I was reading Jon Skeet's refcard on C#. He stated: "Events are closely related to delegates but they are not the same thing." So from my understanding, when events are raised, handlers (delegates) execute the code. I have the following doubts: (1) When we declare an event , will it be registered in any "REGISTERS?" or "System Re...

objective-c delegate

Hello, i working with geocoding at the moment. The geocoding service allways works with delegates. So let's say, I've got a AskingClass and AnsweringClass(geocoding) The AskingClass calls a function in the AnsweringClass to return the adress of the current location. AnsweringClass should handle and capsulate the geocoding stuff. My ...

How to convert delegate from c# to vb.net?

I have this code i'm trying to convert from C# to VB.net: public object Invoke(object instance, object[] inputs, out object[] outputs) { // Create a new, STA thread object[] staOutputs = null; object retval = null; Thread thread = new Thread( delegate(){ ...