我还是不明白:DELPHI开发ASP组件,并返回记录集(200分)

  • 主题发起人 主题发起人 djiang
  • 开始时间 开始时间
D

djiang

Unregistered / Unconfirmed
GUEST, unregistred user!
我看过以前的帖子,实做了一个例子,但有错误:
谁能帮我指出一下错误,或给我一个例子!
我的代码:
unit Test2U;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, AspTlb, test2_TLB, StdVcl,ADODb,ADOdb_TLB, Db;
type
TMyTest = class(TASPObject, IMyTest)
private
fRecordSet:ADOdb_TLB._RecordSet;
protected
procedure OnEndPage;
safecall;
procedure OnStartPage(const AScriptingContext: IUnknown);
safecall;
function Get_P1: _Recordset;
safecall;
procedure myset;
safecall;
end;

implementation
uses ComServ, dmU;
procedure TMyTest.OnEndPage;
begin
inherited OnEndPage;
end;

procedure TMyTest.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
end;

function TMyTest.Get_P1: _Recordset;
begin
Result:=fRecordset;
end;

procedure TMyTest.myset;
var ADOQuery1:TADOQuery;
begin
ADOQuery1:=TADOQuery.Create(nil);
ADOQuery1.Connection := DM.ADOConnection1 ;
ADOQuery1.SQL.Text := 'Select Top 100 * From I_Info_2050';
ADOQuery1.Open ;
fRecordSet:=ADODB_TLB._RecordSet(ADOQuery1.Recordset);
end;

initialization
TAutoObjectFactory.Create(ComServer, TMyTest, Class_MyTest,
ciMultiInstance, tmApartment);
end.

调用时:
<% Set DelphiASPObj = Server.CreateObject("test2.MyTest")
DelphiASPObj.myset()
%>
发生错误:
--------------------------------
错误 '8000ffff'
灾难性故障
/test2/mytest.asp,行9
--------------------------------
 
> ADOQuery1.Connection := DM.ADOConnection1
DM 你确定它已经创建了吗?
 
肯定创建了DM,且ADOConnection1已打开
 
帮帮忙,没人知道吗?
 
如果要给asp调用的话,那么必须这样:
导入MS的ADO库,然后在use里面加入,返回的时候用如下语句:
Result:=iunknown(adoquery1.recordset) as recordset;
 

应该是DM没创建,处理方法:加如下代码,别忘了应用Forms,dmU放在interfer里应用:
...
public
procedure Initialize;override;
destructor Destroy;override;
end;

procedure TMyTest.Initialize;
begin
inherited;
frmdmU:=TfrmdmU.Create(Forms.Application);
end;

destructor TMyTest.Destroy;
begin
frmdmU.free;
inherited;
end;

 
谁能给一个完整的示例吗?
 
后退
顶部