Mega Code Archive

 
Categories / Delphi / ADO Database
 

You need Dynamic ADO object

Title: You need Dynamic ADO object? Question: What shall i do when need to Create many Dynamic ADO object? Answer: Create an array of ADOTable or ADOQuery at nuber you think need! Because you can't find The Dynamic Object that created at other Function or Procedure (test it to be sure)! type // define custom table Dynamic_ado=record ado_t: TADOTable ; // ADO object name: string ; // name of ADO object end ; var ADOT: array [0..100] of Dynamic_ado ; Function createado(name:string;connection:TADOConnection):Boolean ; var i: SHORT ; begin i:=0 ; While TRUE do begin if adot[i].name='' then begin try result:=True ; adot[i].ado_t:=TADOTable.create(nil) ; adot[i].ado_t.Connection:=TADOConnection1 ; adot[i].ado_t.tablename:='accounts' ; adot[i].ado_t.Open ; adot[i].name:=name ; except showmessage('Invalid Connection Or table name') end ; break ; result:=False ; end else inc(i) ; end ; end ; // Moving ADOT to the next record Next Function ado_next(name:string):Boolean ; var i: SHORT ; begin i:=0 ; While TRUE do begin if adot[i].name=name then begin adot[i].ado_t.Next ; result:=True ; if adot[i].Eof then begin ShowMessage('End of DB') ; result:=False ; end ; break ; end else inc(i) ; end ; end ; // You can do similar code for previous , Delete , Last , first or // Destroy table, at last you must destroy the dataset & put it name to the '' (Nothink)