如何使用將 ADODB.Recordset 放入 TADOQuery
發表於 : 2008年 11月 28日, 16:10
在 delphi 中, 若需要一些特殊應用, 希望將 COM 的 ADODB.Recordset 放入 TADOQuery 中, 如何操作呢, 可以利用 IUnknown 介面 (以取得 DefaultInterface) 轉型為 _Recordset 介面即可. 範例程式如下,
代碼: 選擇全部
uses Comobj
.......
var
obj, obj2: OleVariant;
begin
obj := CreateOleObject('ADODB.Stream');
obj2 := CreateOleObject('ADODB.Recordset');
obj.Type := 2 ;
obj.Charset := 'ascii';
obj.Open;
obj.LoadFromFile('c:mydata.xml');
obj2.Open(obj);
ADOQuery1.Recordset := IUnknown(obj2) as _Recordset;
obj2 := UnAssigned;
obj := UnAssigned;
end;