/SQUARE
-
打开上节的工程
-
添加组件
RtcDataProvider2
并设置Server
属性为RtcHttpServer1
-
在
RtcDataProvider2
的OnCheckRequest
事件中写上代码:
with TRtcDataServer(Sender) do
if UpperCase(Request.FileName)='/SQUARE' then
Accept;
- 在
RtcDataProvider2
的OnDataReceived
事件中写上代码:
var
line:integer;
begin
with TRtcDataServer(Sender) do
if Request.Complete then
begin
Write('<html><body>');
Write('Here comes a table of square values ... <br>');
for line:=1 to 100 do
begin
// 使用3个 write 和使用1个效果是一样的
Write('Square of '+IntToStr(line)+' = ');
Write(IntToStr(line*line));
Write('<br>');
end;
Write('......... done.');
Write('</body></html>');
end;
end;
-
编译并运行
-
打开浏览器,分别访问网址
http://localhost/square
、http://localhost/time
细节
-
TRtcDataProvider
只响应自己接收的请求,互不干涉 -
TRtcDataServer(Sender)
VSSender as TRtcDataServer
,考察下as
与强转
的效果和区别 -
使用多个
write()
与使用一个效果一样
带参数的/SQUARE
- 修改
RtcDataProvider2
的OnDataReceived
事件的代码为:
var
cnt,line:integer;
begin
with TRtcDataServer(Sender) do
if Request.Complete then
begin
Write('<html><body>');
Write('Here comes a table of square values ... <br>');
cnt:=0;
if Request.Query['cnt']<>'' then
try
cnt:=StrToInt(Request.Query['cnt']);
except
end;
if (cnt<1)or (cnt>1000) then
begin
cnt:=10;
Write('Wrong "cnt" parameter.');
Write('Using default value of 10.<br>');
end;
for line:=1 to cnt do
begin
Write('Square of '+IntToStr(line)+' = '+IntToStr(line*line));
Write('<br>');
end;
Write('......... done.');
Write('</body></html>');
end;
end;
-
编译并运行
-
打开浏览器,分别访问网址
http://localhost/square
、http://localhost/square?cnt=30
、http://localhost/square?cnt=5392
来源:oschina
链接:https://my.oschina.net/afrusrsc/blog/4705222