delegates

C# Lambdas: How *Not* to Defer "Dereference"?

I'm trying to implement undo functionality with C# delegates. Basically, I've got an UndoStack that maintains a list of delegates implementing each undo operation. When the user chooses Edit:Undo, this stack pops off the first delegate and runs it. Each operation is responsible for pushing an appropriate undo delegate unto the stack. So ...

Create Dependency Properties for setting Custom EventHandlers in XAML

Hi, i want to do add custom event handlers to default framework elements using DependencyProperties. Something like the following: <Border custom:MyProps.HandleMyEvent="someHandler">...</Border> Here is the code behind for the control that contains the Border element: public class MyPage : Page{ public void someHandler(object se...

Objective-C iPhone - Delegating an IBAction from one class to another? Can this be Done?

Hello fellow coders, I have created a class, that makes it easy to enter in the amount for a particular price in the same way an ATM machine allows you to enter in an amount, user does not enter the decimal. This is a generic class called (AmountPicker), so that it can be used among many other classes. I am using it by invoking the pre...

UIView, UIScrollView and UITextFields problem calling Method

I have a view with several embedded UITextFields, this UIView is subordinated to a UIScrollView in IB. Each text field is supposed to invoke a method called updateText defined in the viewcontroller implementation file when the user is done editing the field. For some reason, the method updateText never gets invoked. Anyone have any id...

C# delegates, reference resolution time.

Hi, I have a simple question about .net delegates. Say I have something like this: public void Invoke(Action<T> action) { Invoke(() => action(this.Value)); } public void Invoke(Action action) { m_TaskQueue.Enqueue(action); } The first function encloses a reference to this.Value. During runtime,...

How do I get an IResource from an IEditorActionDelegate

I wrote an IEditorActionDelegate to fire from a context menu on a CompilationUnitEditor. From there I want to create a marker at the start line of the selected text. I have an ITextSelection, and an IEditorPart object. How can I get an IResource from those so that I can call resource.createMarker()? Thanks ...

WinForms Invoke/BeginInvoke

I have a C# win form where I read a file and show lines in a datagridview. Everything works fine.. and I use delegate and Invoke for displaying the lines as they are being read. It also shows a progressbar and does some other stuff like calculating line length and parse the lines to extract certain fields from each line. Just curious, i...

problem with delegate

I've made this to call unmanaged function from C code. pCallback is a function pointer so on the managed side is a delegate. [DllImport("MyDLL.dll")] public static extern Result SetCallback( IntPtr handle, Delegate pCallback, CallbackType Type); Now I am setting public delegate void pfnCallba...

Action<T> vs delegate event

I have seen developers using the below codes quite alternatively. What is the exact difference between these, and which ones go by the standard? Are they same, as Action and Func<T> is a delegate as well: public event Action<EmployeeEventAgs> OnLeave; public void Leave() { OnLeave(new EmployeeEventAgs(this.ID)); } VS public deleg...

Event handler raising method convention

I was just browsing and came across this question: Action vs delegate event The answer from nobug included this code: protected virtual void OnLeave(EmployeeEventArgs e) { var handler = Leave; if (handler != null) handler(this, e); } Resharper also generates similar code when using the "create raising method" quick-fix. My ...

[How-to] Create a Delegate for iphone (in a separate file)

Hey guys, I have been looking for hours and didn't find anything so I decided to give up and ask for your precious knowledge ;) In order to make my code cleaner, I would like to implement the delegate methods of NSXMLParser in another file ... but I couldn't find any tutorials ... Could someone explain me briefly how to do that ? Ch...

Why use BeginInvoke here?

I am looking into someone else's code and do not have much experience with anything to do with multi-threading. I came across this line of code: BeginInvoke((MethodInvoker)delegate() { btnCalibrate.PerformClick(); }); I was wondering why do this when just this would have worked: btnCalibrate.PerformClick(); Thanks for your answers. ...

BeginInvoke throws exception

Hi, I have the following problem. FindRoot is actually in a third party dll and I do not have control over it. It has to be called via Begin invoke. Sometimes, the FindRoot method throws exception. This causes my whole application to crash. Now how do I prevent my application from crashing even if FindRoot throws exception. delegate vo...

Lexical scoping in C# lambda/anonymous delegates

I want to check whether a simple mathematical expression would overflow (using checked and catch(OverflowException)), but without the need to use a try-catch block every time. So the expression (not the result!) should be passed to a function checkOverflow, which then acts accordingly in case of an overflow. This is what I attempted, bu...

Can’t assign to delegate an anonymous method with less specific parameter type

I’m able to assign to delegate object d a method M with less specific parameter type, but if I want to assign to d an anonymous method with same signature as method M, then I get an error. Any idea why that is? class derivedEventArgs : EventArgs { } delegate void newDelegate(object o, derivedEventArgs e); static void Main...

CreateDelegate fails due to delegate signature mismatch...

I am consuming a web service which has a number of methods (50) which create different objects. example: CreateObject1(Object1 obj, int arg2) CreateObject2(Object2 obj, int arg2) ... CreateObjectX(ObjectX obj, int arg2) All Objects (Object1, Object2, ObjectX...) inherit from ObjectBase. So I am trying to do this... delegate void DlgtC...

Problem with Delegates in C#, forms and multiple solutions

EDIT: this is a winform application, sorry for the inconvenience Disclaimer: this is an assignment we got in college, and I'm stuck over this particular section of code. I have 2 solutions in Visual Studio 2008, one for a Form and one for a DLL which the form can use for functionality. The idea is to send HTML mails from the client, an...

How to use delegate pattern on iPhone

hi, I have some questions about using delegate patten on iPhone. This is code using delegate patten. This code works. SecondViewController *secondViewController = [[SecondViewController alloc] init]; secondViewController.delegate = self; [self.navigationController pushViewController:secondViewController animated:YES]; [...

[How-to] Call back a function in the original class

Hey guys, I found some useful information on the web but I still can't manage to do it by myself ;) Ok, let me put my problem in context for you : I have a first class (myViewController) whose declaration is below : // i just give you relevant information RssParser *rssParser; UIActivityIndicator *activityIndicator; In my viewDidL...

Setting animationDidStopSelector: on UIView's animation delegate

I think I've been doing this wrong for the past year and a half of my iPhone development experience... I could use some knowledgeable clarification please! As you may or may not know, UIView properties can be animated quite easily using the beginAnimations:forContext: method, and wrap it up with a commitAnimations call. You can also se...