You are not logged in.
Pages: 1
Hello,
I have next servers/client/models:
FClient := TSQLHttpClientWinHTTP.Create(FServer, FPort, Model);
FDocumentClient := TSQLHttpClientWinHTTP.Create(FDocumentServer, FDocumentPort, DocumentModel);
FLocalModel := LocalModel;
FLocalServer := TSQLRestServerDB.Create(FLocalModel, ChangeFileExt(paramstr(0),'.db3'));
FLocalServer.CreateMissingTables;
FLocalClient := TSQLRestClientDB.Create(FLocalServer);
they are created and work good.
destructor TOmConnectionManager.Destroy;
begin
if sqlite3 = nil then
sqlite3 := TSQLite3LibraryStatic.Create;
FreeAndNil(FModel);
FreeAndNil(FClient);
FLocalClient.Free;
FLocalServer.Free;
FLocalModel.Free;
FDocumentClient.Free;
FDocumentModel.Free;
FreeAndNil(sqlite3);
inherited;
end;
Then I try to destroy them and always get exception in mORMot.pas
destructor TSQLModel.Destroy;
var i,j: integer;
begin
for i := 0 to fTablesMax do begin
with TableProps[i].Props do begin
EnterCriticalSection(fLock); // may be called from several threads at once <---- THEN EXCEPTION HERE
try
for j := 0 to fModelMax do
if fModel[j].Model=self then begin
// un-associate this TSQLRecord with this model
Move(fModel[j+1],fModel[j],(fModelMax-j)*sizeof(fModel[j]));
dec(fModelMax);
break;
end;
TableProps[i].Free;
finally
LeaveCriticalSection(fLock);
end;
end;
end;
inherited;
end;
in VCL everything works good as I see. The problem is in FMX project.
Pls show me the way. Thanks.
Offline
As with any object, you have to destroy them in the reverse order than your creation.
Try to destroy FModel AFTER FClient.
It works "by change" under VCL.
And, BTW what are you doing with the "sqlite3" global variable in your destructor?
Leave the poor variable alone!
Offline
destructor TSQLModel.Destroy;
var i,j: integer;
begin
for i := 0 to fTablesMax do begin
with TableProps[i].Props do begin
EnterCriticalSection(fLock); // may be called from several threads at once <---- THEN EXCEPTION HERE
try
for j := 0 to fModelMax do
if fModel[j].Model=self then begin
// un-associate this TSQLRecord with this model
Move(fModel[j+1],fModel[j],(fModelMax-j)*sizeof(fModel[j]));
dec(fModelMax);
break;
end;
TableProps[i].Free;
finally
LeaveCriticalSection(fLock);
end;
end;
end;
inherited;
end;
Is it okay when "EnterCriticalSection(fLock)" in the code above accesses the fLock property of the class TSQLRecordProperties?! Or is it a bug?
TSQLRecordProperties = class
protected
...
fLock: TRTLCriticalSection;
...
public
Last edited by cypriotcalm (2016-01-14 13:21:37)
Offline
This is on purpose.
The lock is to safely access the fModel[] array.
The code is correct, the problem is in the user code, as I wrote above:
As with any object, you have to destroy them in the reverse order than your creation.
Try to destroy FModel AFTER FClient.
Offline
Pages: 1