在C#中可以用COM直接传递RecordSet类型,请问在Delphi6中可以吗?怎么做? (50分)

  • 主题发起人 主题发起人 zlj555
  • 开始时间 开始时间
Z

zlj555

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢,帮忙拉一下
 
如下:
unit Unit1;
interface
uses
ActiveX, MtsObj, Mtx, ComObj, MTSDEMO_TLB, StdVcl,ADOInt;
type
TMTS1 = class(TMtsAutoObject, IMTS1)
protected
function GetData: OleVariant;
safecall;
//接口函数
function _GetData:OleVariant;
{ Protected declarations }
end;

implementation
uses ComServ;
function TMTS1.GetData: OleVariant;
begin
try
Result := _GetData;
SetComplete;
except
SetAbort;
Raise;
end{try/except};
end;

function TMTS1._GetData: OleVariant;
var
Data : Recordset;
StrConnectionString : string;
begin
{设置名为 mytest 的 ODBC DSN,连接到MyTest的数据库}
strConnectionString := 'DSN=mytest';
Data := CoRecordset.Create;
try
Data.CursorLocation := adUseClient;
Data.Open ('SELECT * from Torder', StrConnectionString,
adOpenKeyset, adLockBatchOptimistic, adCmdText);
// 断开数据库连接
Data.Set_ActiveConnection(nil);
Result := Data;
Finally
// 释放接口
Data := nil;
end{try/finally};
end;

initialization
TAutoObjectFactory.Create(ComServer, TMTS1, Class_MTS1,
ciMultiInstance, tmApartment);
end.
 
调用端又怎么处理呢?OleVariant到rs应该如何处理呢?谢谢
 
接受答案了.
 
后退
顶部