The examples in this section (based on the Packages white paper on the JADE Web site at https://www.jadeworld.com/developer-center/resource-library/white-papers) have a ScheduledEvent class in the exported package. This class has targetMethod, targetContext, and targetObject properties that are supplied to a scheduleEvent method. The targetObject property is an instance of any class in the schema using the package and the targetMethod property is a method on that class or a superclass of that class. The methods to be called in these examples are in the DiaryTester class (a subclass of
The method in the following example schedules an event.
scheduleEvent_click(btn: Button input) updating; begin scheduler.scheduleEvent(whenToInvoke, app, selectEvent.listObject.Method, appContext); end;
The method to schedule an event can include a check that the target method supplied by the user of the package has the same signature as the exampleCallback method (for example, it may expect to call it with the scheduled time) and have the form: shown in the following example.
scheduleEvent(when: Time; targetObject: Object; targetMethod: Method; targetContext: ApplicationContext) updating; vars se : ScheduledEvent; begin if not targetMethod.isCallCompatibleWith(targetObject, Scheduler::exampleCallback) then write 'callback not valid'; return; endif; create se transient; se.targetObject := targetObject; se.targetContext := targetContext; se.targetMethod := targetMethod; se.whenToStart := when; se.myScheduler := self; updateTimer; end;
The method in the following example is called when the timer fires and inspects all events at the start of the queue and calls all those whose time has passed.
causeDueEvents(); vars se : ScheduledEvent; begin foreach se in allScheduledEvents do if se.whenToStart > app.actualTime.time then return; endif; // Call users method, supplying expected start time as a parameter if se.targetObject <> null and se.targetMethod <> null then targetObject.invokeMethod(se.targetContext, se.targetMethod, se.whenToStart); se.myScheduler := null; delete se; endif; endforeach; end;