Thank you very much Frederik, your example works great! ---------- Forwarded message ---------- From: Frederik <scumm_fredo gmx net> Date: Thu, Aug 20, 2009 at 12:08 AM Subject: Re: [Vala] Setting up a timer with callback event To: vala-list <vala-list gnome org> Arkadi Viner wrote:
My code doesn't compile and the problem is: main.vala:77.10-77.19: error: syntax error, expected `(' <b>Process return 256 execution time: 0.729512 s</b> and it points on the lines: public delegate bool <http://references.valadoc.org/glib-2.0/bool.html>SourceFunc (){ return true; } I don't sure what is 'delegate' for but I tried to look for the correct callback function for a timer in valadoc and I found: http://references.valadoc.org/glib-2.0/GLib.SourceFunc.html It looks like this: "public delegate bool <http://references.valadoc.org/glib-2.0/bool.html>SourceFunc ();" so, that's why I have wrote "delegate" for.... So I don't need this "delegate" in my code ?
No. With the "delegate" keyword you define a type for functions. So public delegate bool SourceFunc (); means that the type 'SourceFunc' will represent all functions with no parameters and a boolean return value. When Timeout.add() expects a SourceFunc as second parameter this means that you can pass any function with no parameters and a boolean return value as a parameter. I have attached a compiling version of your code. As Jan has pointed out your callback functions must be inside the class (especially since they access 'timerID'). Make sure that you add the 'my_app_' prefix to your callback functions in Glade: my_app_on_btnActivate_clicked my_app_on_btnDeactivate_clicked These will be the C names of the functions. Best Regards, Frederik _______________________________________________ Vala-list mailing list Vala-list gnome org http://mail.gnome.org/mailman/listinfo/vala-list
Attachment:
timer.vala
Description: Text Data