delegates

Method using Func<T,TResult> as parameters

Hi Guys. I need some help on simplifying my method I have this method public double ComputeBasicAmount(double basicLimit, double eligibleAmt) { return basicLimit * eligibleAmt; } sample usage: Foo foo = new Foo(100, 1000); double basicAmt = ComputeBasicAmount(foo.BasicLimit, foo.EligibleAmt) The problem here is I want the eligib...

Coding Enhancement: Generic Method using Func<T> as parameter

Hi Guys.. I have this two objects class RNB { public RNB(double roomRate, double roomDays) { RoomRate = roomRate; RoomDays = roomDays; } public double RoomRate { get; set; } public double RoomDays { get; set; } public const double BasicLimit = 100; } ...

self.tableView.delegate = self and self.table.dataSource = self memory leak

Hello everyone, I have following codes, which have memory leak on device, could you please kindly help check it? Thanks. @interface NewsListViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> { @private UITableView *tableView; NSFetchedResultsController *fetchedResultsController; ...... } @property (non...

Defining a delegate as a function pointer

I am using a delegate which calls an unmanaged function pointer. This causes the Garbage Collector to collect it before it is used, as described in the CallbackOnCollectedDelegate MDA page on MSDN: MSDN page for CallbackOnCollectedDelegate MDA. The resolution states that I have to marshal the appropriate delegate as an unmanaged functio...

iPhone: invalidate NSTimer from app delegate crashes app

I am trying to run a method from my app delegate, that saves an object in other class as well as invalidates a timer. I have it set up so that when my app exits, it runs the method in my class and saves and stops the timer. In app delegate: - (void)applicationWillResignActive:(UIApplication *)application { // Save the mission bec...

Set delegate in a different class

I'm trying to write my first iPhone app and i'm having some trouble with a delegate. I have a class that utilises the AVAudioPlayer to play some sound, I then have another class that I need to do something when that sound is complete. So I need this class to implement audioPlayerDidFinishPlaying method of the audio player. The problem...

Possible to use UIActionSheet from Application Delegate?

I have a common UIActionSheet which I use across about 10 different view/view controllers. I'm wondering if it's possible to use UIActionSheet from the app delegate in order to prevent code duplication? So far my attempts to use an action sheet from the delegate haven't worked, I suspect my problem lies when calling the showInView metho...

How to convert linq selector into predictor

I have a lambda selector, lets say Func<T, TResult>. Is it possible to convert it into a predictor (Func<T, bool>) using a TResult object as reference? For example, convert x => x.Name into x => x.Name == customerName ...

VB.NET: Threaded function call slower than calling function directly?

I have a function where I am performing a lot number of database operations inside a Sub. The operation when called directly like: ExecProcess() takes about 11 seconds to run. However, if I create a Delegate, and call the sub using BeginInvoke(), the very same process takes over 40 seconds to execute. Here's the threaded code: Prot...

Passing info to a delegate from a UIActionSheet

My understanding about passing data back to a delegate completely revolves around making a new view controller and having it conform to a protocol. I am trying to get a time input back from a UIDatePicker set with the UIDatePickerModeCountDownTimer mode and I am running into issues. Inside of Main1.m I create a UIActionSheet *action, ...

Parameter count mismatch with Invoke?

The code block below results in the error: TargetParameterCountException was unhandled by user code. Parameter count mismatch. public void AddListViewItem(string[] Data) { if (InvokeRequired) { Invoke(new Action<string[]>(AddListViewItem), Data); } else { ListViewD...

UIDatePicker return value data type question

I want to pass back data from a UIDatePicker that is setup like this: UIDatePicker *pickerView = [[UIDatePicker alloc] init]; pickerView.datePickerMode = UIDatePickerModeCountDownTimer; The picker mode is set to be the count down timer. What type of data type do I need to pass back to the delegate? I was thinking it would be somethi...

Curious Performance difference between returning a value or returning through an Action<T> parameter

I was curious to see what the performance differences between returning a value from a method, or returning it through an Action parameter. There is a somewhat related question to this http://stackoverflow.com/questions/2082735/performance-of-calling-delegates-vs-methods But for the life of me I can't explain why returning a value w...

How to replace lambda written in Where clause of Linq with equivalent delegate

I have an Query expression that uses a predicate type and lambda expression. I am getting desired result with this. But I am not clear with how this expression is getting evaluated. I tried to break this lambda expression by creating delegate and replacing condition under Where with delegate type. If I have to rewrite the same thing wi...

[C#] Delegate doesn't accept subclass?

My delegate doens't seem to accept a subclass, I think an example is the easiest. public class A { public A() { } } public class B : A { public B() { } } public class Program { private delegate void CallBack(A a); private static CallBack callBack = new CallBack(Test); public Main(string[] args) { ...

What is the meaning of a delegate inside a class?

I understand delegates as a shortcut for defining a class with one method but what is the meaning of bar2 below? It compiles. But I can't see what an inner class would do here. I know I'm missing something so that's why I'm asking (this is not homework, I'm at work-work right now). namespace ns2 { public delegate void bar();} public ...

c# "OR" event delegates returning bool

Hi, I have created a console for my game in XNA and I have a delegate for when a command has been entered. At the moment the delegate is returning a bool value. I have declared an event inside the Console class (which returns false) and then subscribed to this event from other classes. The idea is, if none of the classes that subscribe ...

Events and delegates, how do I code it 2 levels deep?

Class1 creates and calls a method in Class2. Class2's method updates it progress to an event handler in Class1. But now Class2's method needs to call a method in class3. How can class3 update it's method's progress to class1? Do I need to daisy chain the events and delegates all the way down each level? (I'm using the MVC pattern, The U...

call a delegate from click event using C++/CLI

Hello, In C#, We can call a new function from button click with arguments like this, ////My function public static void Method1(int x) { Console.WriteLine("Method 1"); } and set this function on click event of a command button like this, button1.Click += delegate { mydelegate with argument }; Eg: delegate v...

iphone: uitextfield, multiple textfields with the same delegate??

Hi, there are two different textfields in my applications and i set the .delegate property of both of them to: self. Now i implemented different methods from the uitextfielddelegate protocol but i want to be able to control the two textfields individually. For instance i want the first text field to do something different when editing be...