delegates

Using different delegates for NSXmlParser

I am trying to figure out the best way to design something. I am writing an iPhone App and for the most part I am using async calls to a web service. This means that I cam setting up a URLConnection, calling start and letting it call me back when the data is available or an exception occurs. This works well and I think is the correct way...

C# Delegate Instantiation vs. Just Passing the Method Reference

I have a simple question: what's the advantage of instantiating a C# delegate as opposed to just passing the function reference? What I mean is: Why do: Thread t = new Thread(new ThreadStart(SomeObject.SomeMethod)); When you can do: Thread t = new Thread(SomeObject.SomeMethod); Both will compile and work in my experience...am I m...

EventHandler, event, delegate based programming in Python any example would appreciate?

Basically I'm a C# developer, I know the way C# does, EventHandler, delegate, even... but whats the best way to implement it on Python. ...

Delegate not being called

I have a ContactsViewController which -whenever a row is selected- MessageViewController is opened (using pushViewController). Both the ContactsViewController and the MessageViewController 'register' to receive DatastoreDelegate messages. The weird thing is it all works fine upon loading of my application, but once I navigate to the Mess...

Is there any way to delay- execute a delegate against an IQueryable<T> after/during execution?

I expose an IQueryable method from my business layer for use in other layers. I would like to execute a function against each of the items in the enumeration, once the query has executed down-level. It seems like there should be an event that is raised after the query executes, so that I can then operate on the results from this common...

Simple Delegate (delegate) VS Multicast delegates

I have gone through many articles but I am still not clear about the difference between the normal delegates that we usually create and multicast delegates. public delegate void MyMethodHandler(object sender); MyMethodHandler handler = new MyMethodHandler(Method1); handler += Method2; handler(SOMEOBJECT); The above delegate MyMethodHa...

C++/CLI use of Action<...,...> and Func<...> unsupported?

Hi, it does look like there is support for the Action and Func delegates in the System namespace in C++/CLI. At least not for multiple generic arguments such as: System::Action<int, int>^ action = nullptr; System::Func<int, int>^ func = nullptr; Both result in errors such as: error C2977: 'System::Action' : too many generic arguments...

How should I deal with the need for multiple callbacks for the same delegate in Objective-C?

I have created a library which can download JSON data which is then placed into an NSDictionary. I wrap this class with a simple Twitter engine which allows me to pull my friends timeline, post an update and post an update with my GPS location. From my limited experience with Objective-C the way to connect everything is with delegation. ...

Simple C# event args question...

Im using WPF which has a Storyboard class that has a Completed event. I use it like so: sb.Completed += AddControlToTaskbar; private void AddControlToTaskbar(object sender, EventArgs args) { //... } How to I pass in the EventArgs to my method? Its always null, and I need it to be a custom class Thanks Mark ...

Setting ViewController delegates in iPhone runtime

I am writing an iPhone application and needed to use the address book functionality. For this to work, it is necessary to specify a ABPeoplePickerNavigationControllerDelegate on the ViewController. The problem is that I am creating all fields and buttons dynamically runtime, and thus does not have any custom ViewController - using only ...

Method writing pattern

I recently noticed the following code which basically defines a class method public Func<string, string> SampleMethod = inputParam => { return inputParam.ToUpper(); }; which is the same as doing it in the old fashioned way public string SampleMethod(string inputParam ) { return inputParam.ToUpper(); } My question - why wo...

C# Expression Trees and Invoking a Delegate

So I have a delegate which points to some function which I don't actually know about when I first create the delegate object. The object is set to some function later. I also then want to make an expression tree that invokes the delegate with an argument (for this question's sake the argument can be 5). This is the bit I'm struggling wi...

How can I use the ThreadPool without making Sub foo(o as object) each time?

Every time that I want to make a thread in the ThreadPool I make a stupid little function like Worker_O below. Sub Worker(ByVal i As Integer) 'do important stuff End Sub Sub Worker_O(ByVal o as Object) Worker(CType(o, Integer)) End Sub Sub MakeThread() Dim worker1 as new Threading.WaitCallback(AddressOf Worker_O)) Thre...

ICommand _canExecute problem

Hi, I have the following code and it won't compile because the compiler cannot determine the return type of my CanExecute method. Can someone help me as to what is wrong? class ViewCommand : ICommand { #region ICommand Members public delegate Predicate<object> _canExecute(object param); private ICommand _E...

Assign a delegate that takes parameters

I am looking at the BackgroundWorker.ReportProgress method. It can take 1 param (int) or two params (int, object). If I want to assign the ReportProgress like this: var ReportProgressMethod = backgroundWorker.ReportProgress; I get an error saying that there is an ambiguous reference because (of course) the method can take to sets ...

How to determine if a UIView has a delegate that conforms to a protocol

Howdy all, I have written a custom class that depends significantly on touch dragging/positioning, outside of it's own view boundaries. There is an associated protocol defined with various relevant methods. An example of something that would use this protocol would be a view that allows things to be dropped into it from my custom class....

Checking a MethodInfo against a delegate

How can I determine if a MethodInfo fits a distinct Delegate Type? bool IsMyDelegate(MethodInfo method); Edit: I'm given a MethodInfo object and want to know if it fits the delegate interface. Apart from the obvious private bool IsValidationDelegate(MethodInfo method) { var result = false; var parameters = met...

Closures in C# event handler delegates?

I am coming from a functional-programming background at the moment, so forgive me if I do not understand closures in C#. I have the following code to dynamically generate Buttons that get anonymous event handlers: for (int i = 0; i < 7; i++) { Button newButton = new Button(); newButton.Text = "Click me!"; newButton.Click ...

Creating multicast events with std::tr1::function (or boost::function)

I'm attempting to create C#-like multicast delegates and events using features from TR1. Or Boost, since boost::function is (mostly) the same as std::tr1::function. As a proof of concept I tried this: template<typename T1> class Event { private: typedef std::tr1::function<void (T1)> action; std::list<action> callbacks; public: inli...

Can Delegates cause memory leaks?

Can Delegates cause memory leaks? I mean, by e.g. if a class A contains a ADelegate and the latter points to the BMethod (of B class) can this prevent the A class or B class collection by the GC? If so, how can we "free" delegates (setting ADeletate = Nothing / null?) How do you comment this one: //Class A Finalize, containing ADeleg...