delegates

How to use Delegate in C# for Dictionary<int, List<string>>

The code: [1] private delegate void ThreadStatusCallback(ReceiveMessageAction action, Dictionary<int, List<string>> message); [2] Dictionary<int, List<string>> messagesForNotification = new Dictionary<int, List<string>>(); [3] Invoke(new ThreadStatusCallback(ReceivesMessagesStatus), ReceiveMessageAction.Notif...

Why does this MSDN example for Func<> delegate have a superfluous Select() call?

The MSDN gives this code example in the article on the Func Generic Delegate: Func<String, int, bool> predicate = ( str, index) => str.Length == index; String[] words = { "orange", "apple", "Article", "elephant", "star", "and" }; IEnumerable<String> aWords = words.Where(predicate).Select(str => str); foreach (String word in aWords) ...

very simple delegate musing

Sometimes the simplest questions make me love C/C++ and C# more and more. Today sitting on the bus musing aout delegates I remembered reading somwhere you don't need to use the new keyword when instaniating a new delegate. For example: public static void SomeMethod(string message) { ... } ... public delega...

Using Interface Builder efficiently

I am new to iPhone and objective c. I have spent hours and hours and hours reading documents and trying to understand how things work. I have RTFM or at least am in the process. My main problem is that I want to understand how to specify where an event gets passed to and the only way I have been able to do it is by specifying delegates ...

Are delegates copied during assignment to an event?

Hi, The following code seems to execute the FileRetrieved event more than once. I thought delegates were a reference type. I was expecting this to execute once. I'm going to take a guess and say that the reference is being passed by value, therefore copied but I don't like guesswork :-) public delegate void DirListEvent<T>(T dirItem); ...

Delegate.CreateDelegate() and generics: Error binding to target method

I'm having problems creating a collection of delegate using reflection and generics. I'm trying to create a delegate collection from Ally methods, whose share a common method signature. public class Classy { public string FirstMethod<T1, T2>( string id, Func<T1, int, IEnumerable<T2>> del ); public string SecondMethod<T1, T2>( strin...

Is it possible to pass a structure of delegates from managed to native?

I am writing a wrapper for the game programming library "Allegro" and its less stable 4.9 branch. Now, I have done good insofar, except for when it comes to wrapping a structure of function pointers. Basically, I can't change the original code, despite having access to it, because that would require me to fork it in some manner. I need t...

By using “editingStyleForRowAtIndexPath” method, “didSelectRowAtIndexPath” method is not called

Hi, the delegate method not called -(void)viewWillAppear:(BOOL)animated { [theTableView setEditing:TRUE animated:TRUE]; } -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete; } by calling the above the methods i wi...

handle when callback to a dealloced delegate?

Hi all, I implemented the delegate-callback pattern between two classes without retaining the delegate. But in some cases, the delegate is dealloced. (My case is that I have a ViewController is the delegate object, and when the user press back button to pop that ViewController out of the NavigationController stack) Then the callback m...

applicationDidFinishLaunching not being called on py2app application

applicationDidFinishLaunching on my app delegate is being called when I run my Python-Cocoa app from the Terminal (i.e. python myapp.py). However, if I then use py2app to create an .app bundle, applicationDidFinishLaunching does not get called when I open the .app bundle. ...

PropertyInfo from Delegate

Is there a simple way to get the PropertyInfo for a property in a delegate, assuming it is a simple property seletor? Example: var propertyInfo = Method<MyClass,int>(s => s.Property); ... PropertyInfo Method(Func<T1,T2> selector) { // What goes here? } ...

Moving delegate-related function to a different thread

Hello everybody. We are developing a library in C# that communicates with the serial port. We have a function that is given to a delegate. The problem is that we want it to be run in a different thread. We tried creating a new thread (called DatafromBot) but keep using it as follows (first line): comPort.DataReceived += new Ser...

Properly declare delegation in Objective C (iPhone)

Ok, This has been explained a few times (I got most of the way there using this post on SO), but I am missing something. I am able to compile cleanly, and able to set the delegate as well as call methods from the delegate, but I'm getting a warning on build: No definition of protocol 'DetailViewControllerDelegate' is found I have a De...

NSObject release destroys local copy of object's data

I know this is something stupid on my part but I don't get what's happening. I create an object that fetches data & puts it into an array in a specific format, since it fetches asynchronously (has to download & parse data) I put a delegate method into the object that needs the data so that the data fetching object copies it's formatted a...

are there function pointers in c#?

I am trying to learn some c# coding and wondering if the c++ concept of function pointers is included in c#. I see there are such things as delegates. Are they the same concept? or do they differ on a more fundamental level? ...

Java Micro Edition - HTTP sending/receiving using Threads and Delegates (how to update UI)

Hi there, I'm making a shopping list app which basically uploads your shopping list to a php file and also downloads all the updates anyone else has made to the list. I'm using record stores w/ record enumeration and an item object Basically i want to be able to send off all the elements in the record store to the php file using a thr...

How do I combine similar method calls into a delegate pattern?

I have three methods: public void Save<T>(T entity) { using (new Transaction()) { Session.Save(entity); } } public void Create<T>(T entity) { using (new Transaction()) { Session.Create(entity); } } public void Delete<T>(T entity) { using (new Transaction()) { Session.Delete(entit...

How do i refactor this code by using Action<t> or Func<t> delegates

I have a sample program, which needs to execute 3 methods in a particular order. And after executing each method, should do error handling. Now i did this in a normal fashion, w/o using delegates like this. class Program { public static void Main() { MyTest(); } private static bool MyTest() { ...

NSURLDownload Delegate from different Class

hi, I have a NSURLDownload object in one class file. What I want to do is a different class that calls it becoming its delegate so that the delegate calls such as - (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename gets called. I call the NSURLDownload containing class like this: [[Ac...

Question about Multicast Delegates?

I am going through some exam questions for the 70-536 exam and an actual question one developer posted on his blog has popped up in my exam questions. I cannot remember what his answer was .... but below is the question: You need to write a multicast delegate that accepts a DateTime argument and returns a bool value. Which code segment ...