我用ADO编写一个测试的Active x服务器组件,但只能运行一次,烦劳大侠帮手.(源程序附后)(100分)

  • 主题发起人 主题发起人 adamschen
  • 开始时间 开始时间
A

adamschen

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure Ttestobject.onendpage;
begin
//m_scriptContext:= nil;
m_scriptcontext:=nil;
ADOConnection1.Close;
ADOQuery1.Close;
ADOConnection1.Free;
ADOQuery1.Free;
end;

procedure Ttestobject.onstartpage(const unk: IUnknown);
begin
ADOConnection1:=TADOConnection.create(ADOConnection1);
ADOQuery1:=tADOQuery.create(ADOQuery1);
m_scriptContext:=unk as IScriptingContext;
end;

procedure Ttestobject.test(const temp: WideString);
begin
ADOConnection1.connectionstring:='Provider=SQLOLEDB.1;Password=p;Persist Security Info=True;User ID=wwwuser;Initial Catalog=pre_db;Data Source=nbnt2001;Locale Identifier=2052;Connect Timeout=15;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=CGTEMP';
ADOConnection1.connected:=TRUE;
ADOConnection1.loginprompt:=FALSE;
//ADOConnection1.Provider:=SQLOLEDB.1;
ADOConnection1.connected:=TRUE;
ADOQuery1.connection:=ADOConnection1;
ADOQuery1.SQL.Clear;
ADOQuery1.sql.add('select * from pre_users');
ADOQuery1.Open;
if (not ADOQuery1.Eof) and (temp='123') then
m_scriptContext.Response.Write('ActiveX Test For Delphi');
end;
 
Try:
ADOConnection1:=TADOConnection.create(nil);
ADOQuery1:=tADOQuery.create(nil);
 
procedure Ttestobject.onendpage;
begin
//m_scriptContext:= nil;
m_scriptcontext:=nil;
ADOConnection1.Close;
ADOQuery1.Close;
ADOConnection1.Free;
//wrong!把ADOConnection1释放掉了
ADOQuery1.Free;
//wrong!ADOQuery1释放掉了。应由它们的拥有者释放!!!
end;
 
1、ADOConnection1、ADOQuery1等应该放于Ttestobject类内定义。
2、如Hongjiang所说
 
多人接受答案了。
 
后退
顶部