Page 1 of 1

Connection.AfterDisconnect not triggered

Posted: Sat 08 Apr 2017 07:55
by LHSoft
Hello,
I make an empty project, add a Datamodule unit, place a MSConnection on this Datamodul and link this Datamodule to a SQLServer.
Then I add following code:

Code: Select all

procedure TDataModule2.DataModuleCreate(Sender: TObject);
begin
  MSConnection1.Connect;
end;

procedure TDataModule2.DataModuleDestroy(Sender: TObject);
begin
  MSConnection1.Close;
end;

procedure TDataModule2.MSConnection1AfterDisconnect(Sender: TObject);
begin
  ShowMessage('MSConnection disconnected');
end;
Running this in Delphi XE5 it works like expected, but in Delphi 10.1 the event afterDisconnect is not triggered.
In LiteDAC there is the same behavior.

Is this a bug in Delphi?

best regards
Hans

Re: Connection.AfterDisconnect not triggered

Posted: Tue 11 Apr 2017 12:25
by azyk
The specified behavior does not depend on SDAC/LiteDAC, but the version of Delphi. In the Data.DB unit, the TCustomConnection.SetConnected method implementation for Delphi XE5 there was the condition that triggered the AfterDisconnect event in your sample:

Code: Select all

if Assigned(AfterDisconnect) then AfterDisconnect(Self);
In Delphi 10.1 the condition for trigпrring AfterDisconnect changed:

Code: Select all

if Assigned(AfterDisconnect) and not (csDestroying in ComponentState) then
  AfterDisconnect(Self);
To solve the specified problem, please contact the developers of Delphi 10.1 .