Connection.AfterDisconnect not triggered

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
LHSoft
Posts: 130
Joined: Sat 18 Aug 2012 08:33

Connection.AfterDisconnect not triggered

Post by LHSoft » Sat 08 Apr 2017 07:55

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

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Connection.AfterDisconnect not triggered

Post by azyk » Tue 11 Apr 2017 12:25

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 .

Post Reply