Code: Select all
procedure TForm1.MyQuery1AfterPost(DataSet: TDataSet);
var MyQuery : TMyQuery;
begin
MyQuery := (DataSet as TMyQuery);
if MyQuery.Connection.InTransaction then
begin
MyQuery.Connection.Commit;
end;
end;
procedure TForm1.MyQuery1BeforeEdit(DataSet: TDataSet);
var MyQuery : TMyQuery;
begin
MyQuery := (DataSet as TMyQuery);
if not MyQuery.Connection.InTransaction then
MyQuery.Connection.StartTransaction;
MyQuery.Lock(lrImmediately);
end;
Bu now there is a new property lockmode witch has these options ( lmOptimistic, lmPessimistic and lmNone). If you use the first two, you have to put an event BeforeEdit to call the locking.
Code: Select all
procedure TForm1.MyQuery1BeforeEdit(DataSet: TDataSet);
begin
MyQuery1.Lock;
end;
To solve the problem, you still have to need this code:
Code: Select all
procedure TForm1.MyQuery1AfterPost(DataSet: TDataSet);
var MyQuery : TMyQuery;
begin
MyQuery := (DataSet as TMyQuery);
if MyQuery.Connection.InTransaction then
begin
MyQuery.Connection.Commit;
end;
end;