I am trying to set up a WPF timer, I’ve found C# code and tried converting to Oxygene, but am missing the correct syntax:
I’ve added a method to the window1:
interface
method dispatcherTimer_Tick(sender: Object; e: EventArgs);
implementation
method Window1.dispatcherTimer_Tick(sender: Object; e: EventArgs);
begin
// code will go here
//
end;
Then in my code, included the C# oxidised to Oxygene:
var dispatcherTimer: System.Windows.Threading.DispatcherTimer := new System.Windows.Threading.DispatcherTimer();
//C# Code was dispatcherTimer.Tick += dispatcherTimer_Tick; // I changed it to the line below:
dispatcherTimer.Tick := dispatcherTimer_Tick; // this won’t compile - problem with params
dispatcherTimer.Interval := new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
What’s the correct syntax for assigned the dispatcherTimer_Tick method to the dispatcher.Tick?
var dispatcherTimer: System.Windows.Threading.DispatcherTimer := new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
Btw Oxygene has a very nice feature called “Oxidizer”. You can copy and C# code (say, from browser), then right-click the code editor in VS and issue Oxidizer -> Paste C# as Oxygene:
Thanks for this. I did try Oxidizer, but it gave the line:
dispatcherTimer.Tick := dispatcherTimer.Tick + dispatcherTimer_Tick
which does not compile. I have figured it out, though - it should be:
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
Yeah my colleague missed that part. The big problem here is that oxidizer works with partial code. So it can’t really know “Tick” is an event and thus needs += instead of = … +