delegates

Using delegates to simplify a type safe abstract syntax tree in C# (2.0) currently using the Visitor pattern.

Hi guys, I have some "input" that gets parsed a number of different ways. I'm trying to abstract out the parsing code from the various downstream engines that need the parsed result (some parts will display it, other parts actually execute it, etc. etc.). So far, I have this: interface IParsedNode { // Visits this node, returns wh...

Assign IBOutlet from appDelegate variable in an Array in a view Controller.

Hello Everyone, I have what seams simple, but I just cannot get it to work. I have a variable coming into a ViewController(presented by a modal view) and in the viewController I access the appDelelgate to get at a variable in the passed NSArray. I can verify that the variable is availible with my NSLog just before I make a mess of assig...

A method that executes any time a class property is accessed (get or set) ?

C# - .net 3.5 I have a family of classes that inherit from the same base class. I want a method in the base class to be invoked any time a property in a derrived class is accessed (get or set). However, I don't want to write code in each and every property to call the base class... instead, I am hoping there is a declarative way to "si...

iPhone SDK: viewDidLoad() sees an empty NSArray, but it's populated in a delegate method (MGTwitterEngine)

This is probably obvious, but I'm a bit of a newbie and have spent hours trying to figure this out. In viewDidLoad() I have a call to a function on an MGTwitterEngine object (custom object), with an input. If the request (to Twitter, in this case) is successful, it calls an appropriate delegate method. In viewDidLoad(), it's like thi...

Defining event handlers

I can define an event like this(declared function): MyElement.Keyup +=MyDeclaredFunction I can also define it like this(anonymous delegate): MyElement.Keyup+=new delegate(object sender, eventargs e) {}; I can also define it like this(lambda): MyElement.Keyup += (sender, e) => myfunction What is the best way to do this? One case...

Providing multiple instances of a form yet processing events one at a time

I need to be able to let multiple instances of the same form be open as my application can be used in different places at once. On the other hand i need to be able to process the operations during the "OK" event one at a time to ensure data is stored safely and not overwritten by another form instance by accident. I show my form using t...

ObjC delegate methods never gets called

Hi all, I am creating instances of a class FlickrImage parsing a Flickr API photos response. The class has a method getLocation that does another API call to get the geolocation: NSLog(@"getting location for %i",self.ID); NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; OFFlickrAPIRequest *flickrAPIRequest = [[OFFlickrAPIReq...

Using Delegates in C# Asynchronously

I have the following delegate delegate void UpdateFileDelegate(long maxFileID); That I am calling from a WinForms app like so UpdateFileDelegate FD = new UpdateFileDelegate(ClassInstance.UpdateFile); FD.BeginInvoke(longIDNumber,null,null); It runs asynchronously but the question I have is how can I tell when the Method is done exec...

How to accept ANY delegate as a parameter

I am interested in writing a method that would accept another method as a parameter but do not want to be locked into a specific signature - because I don't care about that. I am only interested whether the method throws an exception when invoked. Is there a construct in the .NET Framework that will allow me to accept any delegate as a ...

C# - Delegate with ref parameter

Is there any way to maintain the same functionality in the code below, but without having to create the delegate? I'm interfacing with a 3rd-party API that contains a number of various DeleteSomethingX(ref IntPtr ptr) methods and I'm trying to centralize the code for the IntPtr.Zero check. private void delegate CleanupDelegate(ref IntP...

Checking whether an `object[] args` satisfies a Delegate instance?

I have the following method signature: public static void InvokeInFuture(Delegate method, params object[] args) { // ... } The delegate and the arguments are saved to a collection for future invoking. Is there any way i can check whether the arguments array satisfies the delegate requirements without invoking it? Thanks. EDIT: ...

Change UIImagePickerController Delegate

I access the camera via UIImagePickerController, and when I set the delegate to self, I can use the delegate methods. However, for what I have planned I need to have the delegate methods in another class, but whenever I try to do that, it will dismiss the the picker whenever I take a picture. When I do this, it works: preview.delegate...

Two methods that differ only in LINQ where part - delegate?

I have a method: internal List<int> GetOldDoctorsIDs { var Result = from DataRow doctor in DoctorTable.Rows where doctor.Age > 30 select doctor.ID List<int> Doctors = new List<int>(); foreach (int id in Result) { //Register getting data Database.LogAccess("GetOldDoctors...

C# Fire and Forget call inside a WebMethod

We have a C# WebMethod that is called synchronously by a Delphi CGI (don't ask!). This works fine except when we switch to our disaster recovery environment, which runs a lot slower. The problem is that the Delphi WinInet web request has a timeout of 30 seconds, which cannot be altered due a Microsoft-acknowledged bug. In the disaster re...

Readymade delegates in ASP.NET 2.0

What are the readymade delegates like delegate void Action<T>(T obj); delegate TOutput Converter<TInput, TOutput>(TInput input); delegate Boolean Predicate<T>(T obj); Function delegate available in ASP.NET 2.0. ...

To update UIProgressView for Multiple File Download (how to use delegate)?

I am trying to update the multiple file download progress value to UIProgressView on a table cell. I have the FileDownloader class which has NSOperationQueue that does asynchronous download operations. I am thinking to update the UI using a "delegate" from FileDownloader class. But I cannot compile the codes. I have FileDownloader as ...

Cast delegate to Func in C#

I have code: public delegate int SomeDelegate(int p); public static int Inc(int p) { return p + 1; } I can cast Inc to SomeDelegate or Func<int, int>: SomeDelegate a = Inc; Func<int, int> b = Inc; but I can't cast Inc to SomeDelegate and after that cast to Func<int, int> with usual way like this: Func<int, int> c = (Func<int,...

Objective-c I get NSObject doesNotRegognizeSelector even though I checked with RespondsToSelector

I have been trying to write a delegate to a view controller which has a method which will call back the sender when it is done -(void) doSomething:(id)target action:(SEL)action object:(id)object{ //Do Some work //Produce an NSArray* called array object = array; if([target respondsToSelector:action]) { [target action]; ...

Changing UI elements from another thread in .NET

I don't get it. If I want to change the text on a button from a thread other than the UI thread in Visual Basic .NET, I need to use a delegate, and do something along the lines of Private Delegate Sub SetTextDelegate(ByVal TheText As String) Private Sub delSetText(ByVal TheText As String) Button1.Text = TheText End Sub Private...

NSNotificationCenter vs delegation( using protocols )?

What are the pros and cons of each of them? Where should I use them specifically? ...