IntraWeb Archive

XI: New component TIWAJAXNotifier

XI: New component TIWAJAXNotifier

In the latest XI release (11.0.9) we introduced the new component TIWAJAXNotifier.

The TIWAJAXNotifier brings a neat feature to IW XI. It is capable of notifying the application when a specific AJAX call was completed. After the AJAX call is completed, the OnNotify event (which also is an AJAX call) of the IWJAXNotifier is triggered and you can perform other tasks, as updating the Database, updating some progress information, etc.

See the sample AJAX call below. At the end of the code, we call IWAJAXNotifier1.Notify. It tells to IW to trigger a new AJAX call when the current one finishes execution.

procedure TIWForm2.ButtonTimeAsyncClick(Sender: TObject; EventParams: TStringList);
begin

  LabelTime.Caption := TimeToStr(Time);
  LabelTime.Visible := True;
  // this will send a notification to the IW AJAX core and a new AJAX call 
  // will be triggered when this AJAX call finishes
  IWAJAXNotifier1.Notify;
end
;

This is the OnNotify event of the TIWAJAXNotifier that is triggered when last AJAX call finishes execution.

procedure TIWForm2.IWAJAXNotifier1Notify(Sender: TObject);
begin

  LabelNotification.Caption := ‘Someone asked the current time and ‘ 
    + ‘the answer was ‘ + LabelTime.Caption;
  LabelNotification.Visible := True;
end
;

You can have several copies of TIWAJAXNotifier in your IW Form thatcan be chained sequentially to update user interface with some progressinformation.

procedure TIWForm2.ButtonExecTasksAsyncClick(Sender: TObject; EventParams: TStringList);
begin

  DoTask;
  LabelTask1.Visible := True;
  IWAJAXNotifier3.Notify;
end
;

procedure TIWForm2.IWAJAXNotifier3Notify(Sender: TObject);
begin

  DoTask;
  LabelTask2.Visible := True;
  IWAJAXNotifier4.Notify;
end
;

procedure TIWForm2.IWAJAXNotifier4Notify(Sender: TObject);
begin

  DoTask;
  LabelTask3.Visible := True;
  IWAJAXNotifier5.Notify;
end
;

procedure TIWForm2.IWAJAXNotifier5Notify(Sender: TObject);
begin

  DoTask;
  LabelTask4.Visible := True;
end
;

The lines of code above shows the usage of the TIWAJAXNotifier chained performing some task and updating user interface at each task completion. See this demo on CodePlex.