level 1
dreamtou2012
楼主
delphi开发的dll,里面用了TSqLconnection,不调用这个过程没事,一但调用,就无法释放,程序停在Freeandlibrary中,假死,主程序无法退出,求救求救!只要调用过程就死了,加载后直接退出没有问题
unit UnitExport;
interface
uses System.Classes,Data.SqlExpr,UnitData,System.SysUtils,Data.DB,activex,
Data.DBXDataSnap,IPPeerClient,Data.DBXCommon, REST.Client, Data.Bind.Components, Data.Bind.ObjectScope,
Datasnap.DBClient, Datasnap.DSConnect, Data.Win.ADODB;
Procedure SetURL(URL:String;Port:String;UserName:String;Password:String);stdcall;
Procedure CloseConnection;stdcall;
Function GetConnection:TSQLConnection;stdcall;
Function SetConnection:Boolean;stdcall;
Function GetConnect:Boolean;stdcall;
var SQLConnect:Boolean;
gURL,gPort,gUserName,gPassword:String;
SQLConnection:TSQLConnection;
type
TSQL = class
public
class procedure SQLConnection1AfterConnect(Sender: TObject);
class procedure SQLConnection1AfterDisconnect(Sender: TObject);
end;
implementation
class procedure TSQL.SQLConnection1AfterConnect(Sender: TObject);
begin
SQLConnect:=True;
end;
class procedure TSQL.SQLConnection1AfterDisconnect(Sender: TObject);
begin
SQLConnect:=False;
end;
Function GetConnect:Boolean;
begin
Result:=SQLConnect;
end;
Procedure CloseConnection;
begin
try
SQLConnect:=False;
SQLConnection.Close;
FreeAndNil(SQLConnection);
except
end;
end;
Function SetConnection:Boolean;
begin
try
SQLConnect:=False;
if SQLConnection<>nil then
SQLConnection.Close;
FreeAndNil(SQLConnection);
except
end;
SQLConnection:=TSQLConnection.Create(nil);
try
SQLConnect:=False;
SQLConnection.Connected:=False;
SQLConnection.ConnectionName:='DataSnapCONNECTION';
SQLConnection.Params.Clear;
SQLConnection.DriverName:='DataSnap';
SQLConnection.Params.Values['DriverName']:='DataSnap';// Add('DriverName=DataSnap');
SQLConnection.Params.Values['DriverUnit']:='Data.DBXDataSnap';
SQLConnection.Params.Values['HostName']:=gURL;
SQLConnection.Params.Values['Port']:=gPort;
SQLConnection.Params.Values['Filters']:='';
SQLConnection.Params.Values['DatasnapContext']:='datasnap/';
SQLConnection.Params.Values['CommunicationTimeout']:='10000';
SQLConnection.Params.Values['CommunicationIPVersion']:='IP_IPv4';
SQLConnection.Params.Values['CommunicationProtocol']:='tcp/ip';
SQLConnection.AfterConnect:=TSQL.SQLConnection1AfterConnect;
SQLConnection.AfterDisconnect:=TSQL.SQLConnection1AfterDisconnect;
SQLConnection.Connected:=True;
except
end;
Result:=SQLConnect;
end;
Function GetConnection:TSQLConnection;
begin
Result:=SQLConnection;
end;
Procedure SetURL(URL:String;Port:String;UserName:String;Password:String);
begin
//Application.Handle:=APP;
gURL:=URL;
gPort:=Port;
gUserName:=UserName;
gPassword:=Password;
end;
exports
GetConnection,
GetConnect,
SetConnection,
SetURL,
CloseConnection;
initialization
CoInitialize(nil);
finalization
CoUninitialize;
end.
2016年07月19日 14点07分
1
unit UnitExport;
interface
uses System.Classes,Data.SqlExpr,UnitData,System.SysUtils,Data.DB,activex,
Data.DBXDataSnap,IPPeerClient,Data.DBXCommon, REST.Client, Data.Bind.Components, Data.Bind.ObjectScope,
Datasnap.DBClient, Datasnap.DSConnect, Data.Win.ADODB;
Procedure SetURL(URL:String;Port:String;UserName:String;Password:String);stdcall;
Procedure CloseConnection;stdcall;
Function GetConnection:TSQLConnection;stdcall;
Function SetConnection:Boolean;stdcall;
Function GetConnect:Boolean;stdcall;
var SQLConnect:Boolean;
gURL,gPort,gUserName,gPassword:String;
SQLConnection:TSQLConnection;
type
TSQL = class
public
class procedure SQLConnection1AfterConnect(Sender: TObject);
class procedure SQLConnection1AfterDisconnect(Sender: TObject);
end;
implementation
class procedure TSQL.SQLConnection1AfterConnect(Sender: TObject);
begin
SQLConnect:=True;
end;
class procedure TSQL.SQLConnection1AfterDisconnect(Sender: TObject);
begin
SQLConnect:=False;
end;
Function GetConnect:Boolean;
begin
Result:=SQLConnect;
end;
Procedure CloseConnection;
begin
try
SQLConnect:=False;
SQLConnection.Close;
FreeAndNil(SQLConnection);
except
end;
end;
Function SetConnection:Boolean;
begin
try
SQLConnect:=False;
if SQLConnection<>nil then
SQLConnection.Close;
FreeAndNil(SQLConnection);
except
end;
SQLConnection:=TSQLConnection.Create(nil);
try
SQLConnect:=False;
SQLConnection.Connected:=False;
SQLConnection.ConnectionName:='DataSnapCONNECTION';
SQLConnection.Params.Clear;
SQLConnection.DriverName:='DataSnap';
SQLConnection.Params.Values['DriverName']:='DataSnap';// Add('DriverName=DataSnap');
SQLConnection.Params.Values['DriverUnit']:='Data.DBXDataSnap';
SQLConnection.Params.Values['HostName']:=gURL;
SQLConnection.Params.Values['Port']:=gPort;
SQLConnection.Params.Values['Filters']:='';
SQLConnection.Params.Values['DatasnapContext']:='datasnap/';
SQLConnection.Params.Values['CommunicationTimeout']:='10000';
SQLConnection.Params.Values['CommunicationIPVersion']:='IP_IPv4';
SQLConnection.Params.Values['CommunicationProtocol']:='tcp/ip';
SQLConnection.AfterConnect:=TSQL.SQLConnection1AfterConnect;
SQLConnection.AfterDisconnect:=TSQL.SQLConnection1AfterDisconnect;
SQLConnection.Connected:=True;
except
end;
Result:=SQLConnect;
end;
Function GetConnection:TSQLConnection;
begin
Result:=SQLConnection;
end;
Procedure SetURL(URL:String;Port:String;UserName:String;Password:String);
begin
//Application.Handle:=APP;
gURL:=URL;
gPort:=Port;
gUserName:=UserName;
gPassword:=Password;
end;
exports
GetConnection,
GetConnect,
SetConnection,
SetURL,
CloseConnection;
initialization
CoInitialize(nil);
finalization
CoUninitialize;
end.