X
xiaogew
Unregistered / Unconfirmed
GUEST, unregistred user!
用过ASP的人都见过下面的语法:
Request.Form(element)[(index)|.Count]
---------------------------------------
dim v
v=Request.Form //返回字符串,表单内容
v=Request.Form("input1") //返回字符串,输入项的值
v=Request.Form("input1")(1) //返回字符串,多选时的一个值
v=Request.Form.Count //返回整数,字符串对个数
v=Request.Form("input1").Count //返回整数,多选时值的个数
注:“input1"为Web页中一个输入项的name属性,下同。
在Delphi中引入ASP的类型库,IRequest、IRequestDictionary声明如下:
IRequest = interface(IDispatch)
.
function Get_Form: IRequestDictionary; safecall;
.
property Form: IRequestDictionary read Get_Form;
.
end;
IRequestDictionary = interface(IDispatch)
function Get_Item(Var_: OleVariant): OleVariant; safecall;
function Get__NewEnum: IUnknown; safecall;
function Get_Count: SYSINT; safecall;
function Get_Key(VarKey: OleVariant): OleVariant; safecall;
property Item[Var_: OleVariant]: OleVariant read Get_Item; default;
property _NewEnum: IUnknown read Get__NewEnum;
property Count: SYSINT read Get_Count;
property Key[VarKey: OleVariant]: OleVariant read Get_Key;
end;
尝试如下代码:
procedure TiwForm.OnStartPage(const AScriptingContext: IUnknown);
var
aContext:IScriptingContext;
aRequest:IRequest;
aDictionary:IRequestDictionary;
tv:variant;
ts:string;
ti:integer;
begin
aContext:=AScriptingContext as IScriptingContext;
aRequest:=aContext.Request;
aDictionary:=aRequest.Form;
tv:=aDictionary; //此句不可少
ts:=tv; //返回字符串
ts=tv('input1') //返回字符串,输入项的值
ts=tv('input1')(1) //返回字符串,多选时的一个值
ti=tv.Count //返回整数,字符串对个数
ti=tv('input1').Count //返回整数,多选时值的个数
.....
end;
在CBuilder测试结果一样。
有没有注意到aDictonary即IRequestDictionary调用的邪门之处,
如何实现这样一个调用方便的接口。
Request.Form(element)[(index)|.Count]
---------------------------------------
dim v
v=Request.Form //返回字符串,表单内容
v=Request.Form("input1") //返回字符串,输入项的值
v=Request.Form("input1")(1) //返回字符串,多选时的一个值
v=Request.Form.Count //返回整数,字符串对个数
v=Request.Form("input1").Count //返回整数,多选时值的个数
注:“input1"为Web页中一个输入项的name属性,下同。
在Delphi中引入ASP的类型库,IRequest、IRequestDictionary声明如下:
IRequest = interface(IDispatch)
.
function Get_Form: IRequestDictionary; safecall;
.
property Form: IRequestDictionary read Get_Form;
.
end;
IRequestDictionary = interface(IDispatch)
function Get_Item(Var_: OleVariant): OleVariant; safecall;
function Get__NewEnum: IUnknown; safecall;
function Get_Count: SYSINT; safecall;
function Get_Key(VarKey: OleVariant): OleVariant; safecall;
property Item[Var_: OleVariant]: OleVariant read Get_Item; default;
property _NewEnum: IUnknown read Get__NewEnum;
property Count: SYSINT read Get_Count;
property Key[VarKey: OleVariant]: OleVariant read Get_Key;
end;
尝试如下代码:
procedure TiwForm.OnStartPage(const AScriptingContext: IUnknown);
var
aContext:IScriptingContext;
aRequest:IRequest;
aDictionary:IRequestDictionary;
tv:variant;
ts:string;
ti:integer;
begin
aContext:=AScriptingContext as IScriptingContext;
aRequest:=aContext.Request;
aDictionary:=aRequest.Form;
tv:=aDictionary; //此句不可少
ts:=tv; //返回字符串
ts=tv('input1') //返回字符串,输入项的值
ts=tv('input1')(1) //返回字符串,多选时的一个值
ti=tv.Count //返回整数,字符串对个数
ti=tv('input1').Count //返回整数,多选时值的个数
.....
end;
在CBuilder测试结果一样。
有没有注意到aDictonary即IRequestDictionary调用的邪门之处,
如何实现这样一个调用方便的接口。