Show/Hide Toolbars

TMS XData Documentation

Events in XData are available in the Events property of the TXDataServerModule object. Such property refers to a TXDataModuleEvents (declared in unit XData.Module.Events) object with several subproperties, each to them related to an event. For example, to access the OnEntityInserting event:

 

uses {...}, XData.Server.Module, XData.Module.Events;
 
// Module is an instance of TXDataServerModule object
Module.Events.OnEntityInserting.Subscribe(
  procedure(Args: TEntityInsertingArgs)
  begin
    // Use Args.Entity to retrieve the entity being inserted
  end
);

 

In a less direct way, using method reference instead of anonymous method:

 

uses {...}, XData.Server.Module, XData.Module.Events;
 
procedure TSomeClass.MyEntityInsertingProc(Args: TEntityInsertingArgs);

begin

  // Use Args.Entity to retrieve the entity being inserted
end;

 

procedure TSomeClass.RegisterMyEventListeners(Module: TXDataServerModule);

var
  Events: TXDataModuleEvents;
begin
  Events := Module.Events;
  Events.OnEntityInserting.Subscribe(MyEntityInsertingProc);

end;

 

Listeners are method references that receive a single object as a parameter. Such object has several properties containing relevant information about the event, and differ for each event type. Names of event properties,  method reference type and arguments follow a standard. The event property is named "On<event>", method reference type is "T<event>Proc" and parameter object is "T<event>Args". For example, for the "EntityInserting" event, the respective names will be "OnEntityInserting", "TEntityInsertingProc" and "TEntityInsertingArgs".

 

All events in XData are multicast events, which means you can add several events handlers (listeners) to the same event. When an event occurs, all listeners will be notified. This allows you to add a listener in a safe way, without worrying if it will replace an existing listener that might have been set by other part of the application.

 

It's always safe to set the events before adding the module and running the server.