1
1Fuyi
Unregistered / Unconfirmed
GUEST, unregistred user!
我用Delphi的WebModule 按Delphi 7帮助中的示例代码做了一个计数器,就是显示不出图像出来
在IIS中巳设置充许允行程序,(实际检测程序运行了的)
但是图像出不来!!!????
在Html中的代码如下
<img src="/jy/prjHit.exe" border=0 alt="计数器">
代码如下:
unit uHit;
interface
uses
SysUtils, Classes, HTTPApp, Jpeg, Graphics;
type
TWebModule2 = class(TWebModule)
procedure WebModule2WebActionHitAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
WebModule2: TWebModule2;
implementation
uses WebReq;
{$R *.DFM}
//<img src="/jy/prjHit.exe" border=0 alt="计数器">
procedure TWebModule2.WebModule2WebActionHitAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
nHit: Integer;
LogFile: Text;
LogFileName: string;
B: TBitmap;
Jpg: TjpegImage;
S: TMemoryStream;
begin
LogFileName := 'Hit.Log';
System.Assign(LogFile, LogFileName);
try
if FileExists(LogFileName) then
begin
Reset(LogFile);
ReadLn(LogFile, nHit);
Inc(nHit);
end
else
nHit := 0;
ReWrite(LogFile);
WriteLn(LogFile, nHit);
finally
Close(LogFile);
end;
Jpg := TJPEGImage.Create;
try
B := TBitmap.Create;
try
B.Width := 50;
B.Height := 18;
B.Canvas.Font.Name := 'AvantGarde Bk BT';
B.Canvas.Font.Size := 10;
B.Canvas.Font.Color := clBlue; //Rgb(255,127,0);
B.Canvas.Font.Style := [fsBold];
B.Canvas.FloodFill(0, 0, clInfoBk, fsSurface);
B.Canvas.TextOut(1, 3, ' ' + IntToStr(nHit));
Jpg.Assign(B);
finally
B.Free
end;
S := TMemoryStream.Create;
Jpg.SaveToStream(S);
Jpg.SaveToFile('1.jpg'); //这句主要是用来测试图像是否生成和刷新,巳刷新
S.Position := 0;
Response.ContentType := 'image/jpeg';
Response.ContentStream := S;
Response.SendResponse;
finally
Jpg.Free;
end;
end;
initialization
if WebRequestHandler <> nil then
WebRequestHandler.WebModuleClass := TWebModule2;
end.
在IIS中巳设置充许允行程序,(实际检测程序运行了的)
但是图像出不来!!!????
在Html中的代码如下
<img src="/jy/prjHit.exe" border=0 alt="计数器">
代码如下:
unit uHit;
interface
uses
SysUtils, Classes, HTTPApp, Jpeg, Graphics;
type
TWebModule2 = class(TWebModule)
procedure WebModule2WebActionHitAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
WebModule2: TWebModule2;
implementation
uses WebReq;
{$R *.DFM}
//<img src="/jy/prjHit.exe" border=0 alt="计数器">
procedure TWebModule2.WebModule2WebActionHitAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
nHit: Integer;
LogFile: Text;
LogFileName: string;
B: TBitmap;
Jpg: TjpegImage;
S: TMemoryStream;
begin
LogFileName := 'Hit.Log';
System.Assign(LogFile, LogFileName);
try
if FileExists(LogFileName) then
begin
Reset(LogFile);
ReadLn(LogFile, nHit);
Inc(nHit);
end
else
nHit := 0;
ReWrite(LogFile);
WriteLn(LogFile, nHit);
finally
Close(LogFile);
end;
Jpg := TJPEGImage.Create;
try
B := TBitmap.Create;
try
B.Width := 50;
B.Height := 18;
B.Canvas.Font.Name := 'AvantGarde Bk BT';
B.Canvas.Font.Size := 10;
B.Canvas.Font.Color := clBlue; //Rgb(255,127,0);
B.Canvas.Font.Style := [fsBold];
B.Canvas.FloodFill(0, 0, clInfoBk, fsSurface);
B.Canvas.TextOut(1, 3, ' ' + IntToStr(nHit));
Jpg.Assign(B);
finally
B.Free
end;
S := TMemoryStream.Create;
Jpg.SaveToStream(S);
Jpg.SaveToFile('1.jpg'); //这句主要是用来测试图像是否生成和刷新,巳刷新
S.Position := 0;
Response.ContentType := 'image/jpeg';
Response.ContentStream := S;
Response.SendResponse;
finally
Jpg.Free;
end;
end;
initialization
if WebRequestHandler <> nil then
WebRequestHandler.WebModuleClass := TWebModule2;
end.