delphi - Delayed DLL directive causing application deadlock on FireDAC query -
i have application set in following manner in delphi xe5:
main.exe: calls function in sub.dll using export delayed directive
function myfunction: boolean; external 'sub.dll' delayed; sub.dll: contains firedac query object runs simple select query.
upon opening query, delayed directive application not terminate when main form closed (process main.exe remains in task manager). process explorer shows thread remaining sub.dll. main.exe process terminates correctly when not specify delayed directive. missing? feel i'm not freeing object can't figure out is.
simplified code:
main.exe:
program main; {$apptype console} {$r *.res} uses system.sysutils; function myfunction: boolean; external 'sub.dll' delayed; begin try myfunction; except on e: exception begin writeln(e.classname, ': ', e.message); readln; end; end; end. sub.dll
library sub; uses system.sysutils, system.classes, dbconn in 'dbconn.pas'; {$r *.res} function myfunction: boolean; export; var conn: tconn; begin conn := tconn.create; conn.destroy; result := true; end; exports myfunction; begin end. dbconn.pas
unit dbconn; interface uses firedac.stan.intf, firedac.stan.option, firedac.stan.error, firedac.ui.intf, firedac.phys.intf, firedac.stan.def, firedac.phys, firedac.stan.pool, firedac.stan.async, firedac.stan.param, firedac.dats, firedac.dapt.intf, firedac.dapt, firedac.vclui.wait, firedac.comp.ui, firedac.phys.odbcbase, firedac.phys.asa, data.db, firedac.comp.dataset, firedac.comp.client; type tconn = class fdconnection: tfdconnection; fdquery: tfdquery; constructor create; destructor destroy; override; end; var conn: tconn; { tconn } implementation constructor tconn.create; begin fdconnection := tfdconnection.create(nil); //set database connection parameters fdconnection begin close; params.clear; params.add('driverid=asa'); params.add('database='); params.add('server='); params.add('user_name='); params.add('password='); open; end; fdquery := tfdquery.create(nil); fdquery begin connection := fdconnection; close; unprepare; sql.clear; sql.add('select first last_name'); sql.add('from users'); sql.add('order last_name'); prepare; open; //this causes deadlock writeln(output, fieldbyname('last_name').asstring); end; end; destructor tconn.destroy; begin fdconnection.close; fdconnection.free; inherited; end; end.
this firedac limitation. see http://docwiki.embarcadero.com/radstudio/xe8/en/dll_development_(firedac)#firedac_dll_unloading
Comments
Post a Comment