请教一个关于 Web Server Application 中全局变量的奇怪问题 ( 积分: 200 )

  • 主题发起人 主题发起人 阳光游子
  • 开始时间 开始时间

阳光游子

Unregistered / Unconfirmed
GUEST, unregistred user!
设想的功能为:
当输入地址 http://localhost/Project1.dll?a=X 时,其中a=后面为测试数据
1、当测试数据不是整数时,提示“请输入整数!”(此功能正常!)
2、当测试数据是整数时,先保存在全局变量S中,再输出S的值(奇怪的是,输出的S总是前一次输入的值,而不是本次输入的值。)

目前程序代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, HTTPApp;
type
TWebModule1 = class(TWebModule)
PageProducer1: TPageProducer;
procedure WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
procedure PageProducer1HTMLTag(Sender: TObject; Tag: TTag;
const TagString: String; TagParams: TStrings;
var ReplaceText: String);
private
{ Private declarations }
function aa(a:String;var Response: TWebResponse):Boolean;
public
{ Public declarations }
end;

var
WebModule1: TWebModule1;
s:String;

implementation

{$R *.DFM}

function TWebModule1.aa(a:String;var Response: TWebResponse):Boolean;
begin
Result := StrToIntDef(a,0)=StrToIntDef(a,1);
if not Result then Response.Content := '<SCRIPT language=JavaScript>alert(''请输入整数!'');</SCRIPT>'
else s := a;
end;

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
Result : Boolean;
begin
if not aa(Request.QueryFields.Values['a'],Response) then Exit;
end;

procedure TWebModule1.PageProducer1HTMLTag(Sender: TObject; Tag: TTag;
const TagString: String; TagParams: TStrings; var ReplaceText: String);
begin
if TagString='aaa' then ReplaceText := s;
end;

end.

请各位前辈指教,谢谢`````````````````
 
设想的功能为:
当输入地址 http://localhost/Project1.dll?a=X 时,其中a=后面为测试数据
1、当测试数据不是整数时,提示“请输入整数!”(此功能正常!)
2、当测试数据是整数时,先保存在全局变量S中,再输出S的值(奇怪的是,输出的S总是前一次输入的值,而不是本次输入的值。)

目前程序代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, HTTPApp;
type
TWebModule1 = class(TWebModule)
PageProducer1: TPageProducer;
procedure WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
procedure PageProducer1HTMLTag(Sender: TObject; Tag: TTag;
const TagString: String; TagParams: TStrings;
var ReplaceText: String);
private
{ Private declarations }
function aa(a:String;var Response: TWebResponse):Boolean;
public
{ Public declarations }
end;

var
WebModule1: TWebModule1;
s:String;

implementation

{$R *.DFM}

function TWebModule1.aa(a:String;var Response: TWebResponse):Boolean;
begin
Result := StrToIntDef(a,0)=StrToIntDef(a,1);
if not Result then Response.Content := '<SCRIPT language=JavaScript>alert(''请输入整数!'');</SCRIPT>'
else s := a;
end;

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
Result : Boolean;
begin
if not aa(Request.QueryFields.Values['a'],Response) then Exit;
end;

procedure TWebModule1.PageProducer1HTMLTag(Sender: TObject; Tag: TTag;
const TagString: String; TagParams: TStrings; var ReplaceText: String);
begin
if TagString='aaa' then ReplaceText := s;
end;

end.

请各位前辈指教,谢谢`````````````````
 
呵呵web application本来就是多线程的,你用全局变量安全吗?
 
请问,如果不用全局变量,该如何实现上述设想的功能?
 
unit Unit1;

interface

uses
SysUtils, Classes, HTTPApp;

type
TWebModule1 = class(TWebModule)
procedure WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
function aa(a: string; var Response: TWebResponse): Boolean;
end;

var
WebModule1: TWebModule1;

implementation

{$R *.dfm}
function TWebModule1.aa(a: string; var Response: TWebResponse): Boolean;
begin
Result := StrToIntDef(a, 0) = StrToIntDef(a, 1);
if not Result then Response.Content := '<SCRIPT language=JavaScript>alert(''请输入整数!'');</SCRIPT>'
else Response.Content := a;
end;


procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
Result: Boolean;
begin
if not aa(Request.QueryFields.Values['a'], Response) then Exit;
end;

end.
 
后退
顶部