by
dcooper@jade.co.nz >> Wed, 7 Apr 2004 7:18:31 GMT
Pick an object (the target) that *is* known to both the subscriber (the process that does the beginNotification) and the process that raises the notification (causes the events).
Typically you'll want a persistent object for this. If you're wanting to write a form that keeps track of all actions for a user, then presumably you've got a class in your system (User, for example) for which there is one persistent instance for each user that can sign on. If so, then you could set up your notifications something like:
1. Have a combo box or something on your monitor form that lets you pick the persistent User object whose actions you want to monitor. When this is clicked, do something like:
// easy way to end all notifications
endNotificationForSubscriber(self); // self is the form
// subscribe to notifications for the selected userbegin Notification(userCombo.itemObject.User, UserEvent,
Response_Continuous, 0);
UserEvent is a constant Integer representing the event and should be greater than the RootSchema's User_Base_Event global constant (16).
2. Presumably you have a reference somewhere (app.myUser, for example) that references the currently signed-on user for a process (eg: it's set when a user signs on). Given this, anywhere that you want to cause an event that is to be tracked by any open monitor form, you can just code:
infoString := ...some details about the event...; app.myUser.causeEvent(UserEvent, true, infoString);
Passing "true" for the second parameter indicates that the event is to be caused immediately - I've assumed this is what you want. If you pass "false" for this parameter, then the event will be caused only at the next commitTransaction. This is useful when you want to cause events that you know will be dispatched only when the current transaction commits successfully. Use infoString to pass through details about the event if required (eg: a string to display in a listbox on your form, for example). This is limited to 49K in size. If not required, just pass null.
3. The userNotify method on your monitor form would look something like:
userNotify(eventNo: Integer; obj: Object; tag: Integer; info: Any) updating; vars
infoString : String;begin
if eventNo = UserEvent then
infoString := info.String;
...update the form and display infoString somewhere...
endif;
end;
If you have lots of different events then you may want to have a constant per event (ie: instead of UserEvent, you have UserEventA, UserEventB, UserEventC, etc) and cause specific notifications for each one. This would mean that your form would have to register for several notifications, but you could then allow the user to select the events that they're interested in. Depends on what you want.
Cheers,
Dean.