delphi - Delphi2005 - Using TADOQuery Results in another method -
because of code redundancy generalized usual adoquery handling method of own, method returning _recordset of query. now, when check query results inside method, check out alright. returned _recordset seems empty or nil (exception: eoleexception 'item cannot found in collection corresponding name or ordinal.') gathered, seem need return clone of query's _recordset. far have tried using
res := qr.recordset.clone(adlockunspecified); result := res;
,
tadoquery.recordset._xclone()
method
unsuccessfully, these methods, none of worked (several components not recognized, version differences i'm guessing).
the code use querying:
function querydb(const s: widestring; const dc: boolean = true): _recordset; var ds: string; conn: tadoconnection; qr: tadoquery; res: _recordset; begin result := nil; conn := tadoconnection.create(nil); qr := tadoquery.create(nil); try ds := 'provider=microsoft.jet.oledb.4.0;data source=' + extractfilepath(application.exename) + 'gdkp.mdb;persist security info=false'; conn.connectionstring := ds; conn.loginprompt := false; conn.connected := true; qr.connection := conn; if(dc = true)then begin qr.disablecontrols end; qr.sql.add(s); qr.open; result := qr.recordset; conn.free; qr.free; end; end;
has overcome problem before , knows suitable answer or can direct me towards helpful content?
i don't know of crazy antics more crazy:
setting , connecting database inside function , doing queries inside function, connecting database each time query, going insanely slow.
ado query objects should have longer lifetime insides of function. code smell, severe one.
keep recordset inside query belongs.
-
normal people create tdatamodules , leave objects around lifetime of app, , requery using code:
query.active := false; query.active := true;
watch app speed when doesn't have connect database, create , tear down connection , query, each time want data.
what on earth doing _recordsets youre getting back? did learn ado in c# , you're trying use c# ado.net idioms in delphi? don't. stop doing that.
Comments
Post a Comment