如下:
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.