I have a common idiom in a system I developing on the UI forms that employ Delphi LiveBindings that are bound to TObjectList. Front-end is Delphi using async method calls to a REST server using TRESTRequest.ExecuteAsync(). For the INSERT/UPDATE/DELETE activity, I am placing my code to carry out the rest call in a BindSourceAdapter.OnListInsert/OnListDelete/etc event handler.
This issue I have is that those event handlers seem to expect an response that can only be known with a synchronous call. For example, OnListDelete has the implementer set "ADeleted" to indicate whether or not the item was removed from the ObjectList.
In the code example below, I am waving my hands over the problem at the moment because I don't know the right way to handle it. But "DeleteConnector" contains the async call to make the call to mod the resource and returns before the response is received. In the main thread, it returns PDQ but the delete may fail because of a DB constraint, for example.
What is the proper way to keep the the bound UI list in sync with the back-end state?
procedure TCNSConnectorFrame.ConnectorListOnDelete
(Sender: TBindSourceAdapter; AIndex: Integer;
var AHandled, ADeleted: Boolean);
begin
AHandled := true;
ADeleted := true;
DeleteConnector;
end;
I can punt by switching the POST/PUT/DELETE calls to blocking calls. I can punt by switching to a non-LiveBindings implementation to give me more granular control over the UI state.
Before I take such action, i want to make sure I am not overlooking something basic. I am fairly new to multi-threaded coding.
First-ever question here, but long time lurker. TIA.