Hi Guys
I was doing some digging around into delegate variance after reading the following question in SO : http://stackoverflow.com/questions/2714989/delegate-createdelegate-and-generics-error-binding-to-target-method
I found a very nice bit of code from Barry kelly at
https://www.blogger.com/comment.g?blogID=8184237816669520763&...
In C# 2.0, I can do the following:
public class MyClass
{
delegate void MyDelegate(int myParam);
public MyClass(OtherObject obj)
{
//THIS IS THE IMPORTANT PART
obj.SomeCollection.Add((MyDelegate)MyFunction);
}
private void MyFunction(int myParam);
{
//...
}
}
Trying to implem...
Hello, I am using a NSXMLParser class in my program and I assign a delegate to it.
This delegate, though, gets retained by the setDelegate: method resulting to a minor, yet annoying :-), memory leak.
I cannot release the delegate class after the setDelegate: because the program will crash.
Here is my code:
self.parserDelegate = [[Pars...
I am trying to disable parts of the UI in a .NET app based on polling done on a background thread. The background thread checks to see if the global database connection the app uses is still open and operable.
What I need to do, and would prefer to do it without polling on the UI thread, is to add an event handler that can be raised by...
Is it possible to use the new lambda expressions in Visual C++ 2010 as CLR event handlers? I've tried the following code:
SomeEvent += gcnew EventHandler(
[] (Object^ sender, EventArgs^ e) {
// code here
}
);
It results in the following error message:
error C3364: 'System::EventHandler' : invalid argument for deleg...
public class Program
{
delegate void Srini(string param);
static void Main(string[] args)
{
Srini sr = new Srini(PrintHello1);
sr += new Srini(PrintHello2); //case 2:
sr += new Srini(delegate(string o) { Console.WriteLine(o); });
sr += new Srini(deleg...
Why does...
type IntDelegate = delegate of int -> unit
type ListHelper =
static member ApplyDelegate (l : int list) (d : IntDelegate) =
l |> List.iter (fun x -> d.Invoke x)
ListHelper.ApplyDelegate [1..10] (fun x -> printfn "%d" x)
not compile, when:
type IntDelegate = delegate of int -> unit
type ListHelper =
stat...
I am having trouble figuring out how to use the JQuery delegate function to do what I require. Basically, I need to allow users to add Panels (i.e. divs) to a form dynamically by selecting a button. Then when a user clicks a button within a given Panel, I want to be able to to something to that Panel (like change the color in this exam...
I recently found myself needing a typesafe "fire-and-forget" mechanism for running code asynchronously.
Ideally, what I would want to do is something like:
var myAction = (Action)(() => Console.WriteLine("yada yada"));
myAction.FireAndForget(); // async invocation
Unfortunately, the obvious choice of calling BeginInvoke() without a ...
Hello,
I have a class with a delegate declaration as follows...
Public Class MyClass
Public Delegate Function Getter(Of TResult)() As TResult
''#the following code works.
Public Shared Sub MyMethod(ByVal g As Getter(Of Boolean))
''#do stuff
End Sub
End Class
However, I do not want to explicitly type the...
Hello...
I just go the answer on how to pass a generic delegate as a parameter. Thanks for the help. Now I need to know how to ASSIGN the delegate to another delegate declarartion. Can this be done?
Public Class MyClass
Public Delegate Function Getter(Of TResult)() As TResult
''#the following code works.
Public Sh...
Well, the problem is that I've got a lot of code like this for each event passed to the GUI, how can I shortify this? Macros wont do the work I guess. Is there a more generic way to do something like a 'template' ?
private delegate void DownloadProgressDelegate(object sender, DownloaderProgressArgs e);
void DownloadProgress(object sende...
In my other methods I could do something like this,
public void Add(T item)
{
if (dispatcher.CheckAccess())
{
...
}
else
{
dispatcher.Invoke(new Action<T>(Add), item);
}
}
But how do I invoke a property for a situation like this?
public T this[int...
Hi i am new to iphone developement , can any one explain me , why setDelegate is used, where we should use it.
[request setDelegate:sender];
thanks in advance.
...
Consider a class with these methods:
- (id) initWithFrame: (CGRect) frame
{
if (!(self = [super init]))
return nil;
webView = [[UIWebView alloc] initWithFrame:frame];
[webView setDelegate:self];
lock = [[NSConditionLock alloc] initWithCondition:LOCK_WAIT];
return self;
}
- (void) setHTML: (NSString *) html
{...
Hi,
I am using jquery 1.4.2 and trying to achieve the following:
1 - function call that sends a value to a php page to add/remove an item
2 - returns html list of the items
3 - list should still be sortable
4 - save (serialise list) onclick
My full WIP is located here [http://www.chittak.co.uk/test4/index_nw3.php][1]
I tried to d...
static void Main()
{
string[] a = { "a", "asd", "bdfsd", "we" };
a = a.OrderBy(fun).ToArray();
}
private static int fun(string s)
{
return s.Length;
}
its is giving compile time error . I know that we can do this with Lambda expression like this. a.OrderBy(s=>s.Length).ToArray(); but i ...
@interface ClassB <ClassADelegate> : ClassA
id <ClassBDelegate> delegate;
@end
As the code says, ClassB subclasses from ClassA and handles the formation protocol of Class A. However, the variable "delegate" will be duplicated. (ClassA also has "delegate")
In fact, it can be done without subclassing, but it seems the code is cumberso...
Hello,
In the last couple of days I asked a couple of questions about delegates HERE and HERE.
I confess...I don't really understand delegates. And I REALLY REALLY REALLY want to understand and master them. (I can define them--type safe function pointers--but since I have little experience with C type languages it is not really helpfu...
In my domain layer all domain objects emit events (of type InvalidDomainObjectEventHandler) to indicate invalid state when the IsValid property is called.
On an aspx codebehind, I have to manually wire up the events for the domain object like this:
_purchaseOrder.AmountIsNull += new DomainObject.InvalidDomainObjectEventHandler(HandleDo...