update a display jade object manager sysnotify endnotification beginnotification share price change...
Post on 29-Dec-2015
215 Views
Preview:
TRANSCRIPT
Update a Display
JADEObjectManager
sysNotify
endNotification
BeginNotification
Sharepricechange
$1.25Brierley
(userNotify)
(causeEvent)
beginNotification
Process Communication
JADEObjectManager
userNotify
causeEventsystem
or a shared transient
object
process 1
process 2
(endNotification)
Subscribing
• Object– specific object
for example, notify if Brierley price changes
– use beginNotification and endNotification
• Class– all objects in a class (or subclass)
for example, notify if any share price changes
– use beginClassNotification and endClassNotification
System Notification
eventType - 0 (Any_System_Event)
- 3 (Object_Update_Event)
- 4 (Object_Create_Event)
- 6 (Object_Delete_Event)
theObject - Persistent object that was updated, created or deleted
eventTag - Integer specified in the beginNotification
or beginClassNotification
Note: System events are only available for persistent objects
sysNotify (eventType, theObject, eventTag)
JADEObjectManager
sysNotify
endNotification
beginNotification
Sharepricechange
$1.25Brierley
Example - sysNotify
1
4
2
3
load() updating;begin
self.beginClassNotification(Share, false, Object_Update_Event, Response_Continuous, 0);end; // Share Watch form
load() updating;begin
self.beginClassNotification(Share, false, Object_Update_Event, Response_Continuous, 0);end; // Share Watch form
sysNotify(eventType : Integer; theObject : Object; eventTag : Integer) updating; begin
app.msgBox(theObject.Share.name & " has changed", "Notification Message", MsgBox_OK_Only);
end; // Share Watch form
sysNotify(eventType : Integer; theObject : Object; eventTag : Integer) updating; begin
app.msgBox(theObject.Share.name & " has changed", "Notification Message", MsgBox_OK_Only);
end; // Share Watch form
unload() updating;begin
self.endClassNotification(Share, false, Object_Update_Event);end; // Share Watch form
unload() updating;begin
self.endClassNotification(Share, false, Object_Update_Event);end; // Share Watch form
1
3
4
Example - sysNotify
User Notification
eventType - 16 to 232 -1 corresponding to integer
specified in the causeEvent method
theObject - Object causing the notification
eventTag - Integer specified in the beginNotification
or beginClassNotification method
userInfo - Primitive value or object reference
specified in causeEvent method
userNotify (eventType, theObject, eventTag, userInfo)
Example - userNotify
JADEObjectManager
userNotify
endNotification
beginNotification
Sharepricechange
$12.25Brierley
1
4
2
3
causeEvent
load() updating;constants Sell_Now = 43; // Sell_Now should be a Global constant
begin self.beginClassNotification(Share, false, Sell_Now, Response_Continuous, 0);end; // Share Watch form
load() updating;constants Sell_Now = 43; // Sell_Now should be a Global constant
begin self.beginClassNotification(Share, false, Sell_Now, Response_Continuous, 0);end; // Share Watch form
price(set : Boolean; _value : Decimal io) mapping;constants Sell_Now = 43 ; // Sell_Now should be a Global constant
begin if _value >= 10.00 then self.causeEvent(Sell_Now, true, 0); endif; end; // Share object
price(set : Boolean; _value : Decimal io) mapping;constants Sell_Now = 43 ; // Sell_Now should be a Global constant
begin if _value >= 10.00 then self.causeEvent(Sell_Now, true, 0); endif; end; // Share object
2
1
Example - userNotify
userNotify(eventType:Integer; theObject:Object; eventTag:Integer; userInfo:Any) updating;
begin
app.msgBox("Sell shares in " & theObject.Share.name, "Selling Instruction", MsgBox_OK_Only);
end; // Share Watch form
userNotify(eventType:Integer; theObject:Object; eventTag:Integer; userInfo:Any) updating;
begin
app.msgBox("Sell shares in " & theObject.Share.name, "Selling Instruction", MsgBox_OK_Only);
end; // Share Watch form
3
unload() updating;
constants Sell_Now = 43 ; // Sell_Now should be a Global constant
begin
self.endClassNotification(Share, false, Sell_Now);end; // Share Watch form
unload() updating;
constants Sell_Now = 43 ; // Sell_Now should be a Global constant
begin
self.endClassNotification(Share, false, Sell_Now);end; // Share Watch form
4
Using userInfo
• Parameter passed by causeEvent method
• Parameter that can be read in userNotify event
• Can be used to hold reference to any class or primitive type information because it is of type of Any
• theObject parameter holds a reference to the object that caused the notification
Why use Notifications
• Avoids the continual checking to see if something has happened
• No “sleep ... wake up ... check ...” sequence wasting processor cycles
• Decouples processes
• Handles random event sequences
• Easy to code and implement
When to use Notifications
• When random events occur
• Want to avoid continual checking
• Displayed information has to be up to date
• Cache synchronisation
• Critical events must be monitored and acted upon instantly
• Do Not Overuse, always justify the use of a notification
• Consider object instead of class scope or even causeEvent
Challenge #24• Load a custom ThreeDeeGraph control• Paint a Statistics form• Add a drawBarGraph method• Code load method of form
name mnuCustomerStatistics
caption &Statistics
• Add a menu item to MainMenu
name threeDeeGraph
Challenge #25
• Subscribe to notifications on the Customer and BankAccount classes when the form is loaded
• Respond to notifications by redrawing the graph
• Unsubscribe to notifications when the form is closed
• Test the notifications by adding customers with the Statistics form open
top related