我用Delphi7开发了个ASP定时组件代码如下:
unit Main;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows,Dialogs,ComObj, ActiveX, AspTlb, Timer_TLB, StdVcl;
type
Tsleep = class(TASPObject, Isleep)
private
st:Longint;
proc:TFarProc;
lhnd:THandle;
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
function Get_stime: Integer; safecall;
procedure Set_stime(Value: Integer); safecall;
procedure SleepTime; safecall;
end;
implementation
uses ComServ;
type
TSleeps = procedure(dwMilliseconds:WORD);stdcall;//dwMilliseconds sleep time in milliseconds
var
ts:TSleeps;
procedure Tsleep.OnEndPage;
begin
inherited OnEndPage;
end;
procedure Tsleep.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
end;
function Tsleep.Get_stime: Integer;
begin
Result:=st;
end;
procedure Tsleep.Set_stime(Value: Integer);
begin
st:=Value;
end;
procedure Tsleep.SleepTime;
begin
lhnd:=LoadLibrary('kernel32.dll');
if lhnd>0 then
begin
try
proc:=GetProcAddress(lhnd,Pchar('Sleep'));
if proc<>nil then
begin
ts:=TSleeps(proc);
ts(st);
end
else
ShowMessage('函数没有找到');
finally
FreeLibrary(lhnd);
end//end try
end
else
begin
ShowMessage('dll没找到');
end;
end;
initialization
TAutoObjectFactory.Create(ComServer, Tsleep, Class_sleep,
ciMultiInstance, tmApartment);
end.
编译生成Timer.dll,拷贝到C:\windows\system32下,regsvr32 Timer.dll,注册成功
在ASP中的代码如下:
<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H2> Timer测试 </H2>
</CENTER>
<HR>
<% Set DelphiASPObj = Server.CreateObject("Timer.sleep")
DelphiASPObj.stime=3000
response.write DelphiASPObj.stime&"<br><br>"
DelphiASPObj.SleepTime
response.write DelphiASPObj.stime&"<br><br>"
DelphiASPObj.SleepTime
response.write DelphiASPObj.stime&"<br><br>"
DelphiASPObj.SleepTime
Set DelphiASPObj =nothing
%>
<HR>
</BODY>
</HTML>
但是ASP页面根本就显示不出来,请教如何解决?怎么样可以让属性值被定期读出?在线等待答案…………………………
附件是程序包