Hello Wagner,
I don't know, should TXDataAureliusModel.Get be thread safe?
I have this code:
procedure TdmSngModel.DoSetConnection( const AUrl, AToken, AModel: String);
begin
DoLog( loaTraceAll, '~~ DoSetConnection ~ Enter ~ ' + AModel);
FToken := AToken;
xClient.Free;
FConnectedModel := AModel;
FXDataModel := TXDataAureliusModel.Get( FConnectedModel);
xClient := TXDataClient.Create( FXDataModel);
xClient.Uri := AUrl;
xClient.HttpClient.OnSendingRequest := xClientOnSendingRequest;
// xClient.ReturnedInstancesOwnership := TInstanceOwnership.None;
xsngFunc := xClient.Service<IsngFunc>;
FDatasetControl := TDatasetControl.Create( Self);
DoLog( loaTraceAll, '~~ DoSetConnection ~ Exit ~ ' + AModel);
end;
The line: FXDataModel := TXDataAureliusModel.Get( FConnectedModel);
makes the problem.
It often happens that this method is called multiple times. Of course from different threads.
I have a log from a second "Enter" before the first "Enter" logs "Exit".
There is an exception at the second entry at the Model.Get position.
"Duplikate nicht zulässig" in german. I think in english version: "Duplicates not allowed".
This is triggered by a TDictionary.
I'm not sure if that's the trigger. Debugging is difficult.
Can I get the model in a thread-safe manner?
Thomas