当前位置:首页 > 网络编程 > 软件语言 > DELPHI > 用Delphi编写CGI程序返回图象

用Delphi编写CGI程序返回图象

点击次数:46 次 发布日期:2008-11-09 08:38:36 作者:源代码网
源代码网推荐
广告载入中
Delphi 对Internet编程提供了强大的支持,Delphi 编写CGI非常容易,Dlphi 本身提供了例程。但是笔者在实践中遇到需要CGI程序根据数据库动态 返回图象的情况,很多文章推进使用Cgi-Expert或有关的OCX控件,使用控件不仅 带来额外的开销,且缺乏灵活性,那么能否不使用这些控件自己编写代码实现,现 推荐一种方法,代码如下:
源代码网推荐
源代码网推荐 unit ChartMod;
源代码网推荐
源代码网推荐 interface
源代码网推荐
源代码网推荐 uses
源代码网推荐 Windows, Messages, SysUtils, Classes,
源代码网推荐 HTTPApp, Db, DBTables,
源代码网推荐 DbChart, Series, Jpeg, ExtCtrls;
源代码网推荐
源代码网推荐 type
源代码网推荐 TWebModule1 = class(TWebModule)
源代码网推荐 Table1: TTable;
源代码网推荐 procedure WebModule1ActionAreaAction
源代码网推荐 (Sender: TObject;
源代码网推荐 Request: TWebRequest; Response:
源代码网推荐 TWebResponse; var Handled:
源代码网推荐 Boolean);
源代码网推荐 procedure WebModule1ActionPopulationAction
源代码网推荐 (Sender: TObject;
源代码网推荐 Request: TWebRequest; Response:
源代码网推荐 TWebResponse; var Handled:
源代码网推荐 Boolean);
源代码网推荐 procedure WebModule1Create(Sender: TObject);
源代码网推荐 procedure WebModule1Destroy(Sender: TObject);

源代码网推荐 procedure WebModule1AfterDispatch(Sender: TObject;
源代码网推荐 Request: TWebRequest; Response:
源代码网推荐 TWebResponse; var Handled: Boolean);
源代码网推荐 private
源代码网推荐 Chart: TDBChart;
源代码网推荐 Series: TPieSeries;
源代码网推荐 Image: TImage;
源代码网推荐 public
源代码网推荐 { Public declarations }
源代码网推荐 end;
源代码网推荐
源代码网推荐 var
源代码网推荐 WebModule1: TWebModule1;
源代码网推荐
源代码网推荐 implementation
源代码网推荐
源代码网推荐 {$R *.DFM}
源代码网推荐
源代码网推荐 procedure TWebModule1.WebModule1ActionAreaAction(
源代码网推荐 Sender: TObject;
源代码网推荐 Request: TWebRequest; Response: TWebResponse;
源代码网推荐 var Handled: Boolean);
源代码网推荐
源代码网推荐 begin
源代码网推荐 // set specific values
源代码网推荐 Chart.Title.Text.Clear;
源代码网推荐 Chart.Title.Text.Add ("Area of Countries");
源代码网推荐 Chart.LeftAxis.Title.Caption := "Area";
源代码网推荐 Series.Title := "Area";
源代码网推荐 Series.PieValues.ValueSource := "Area";
源代码网推荐 end;
源代码网推荐
源代码网推荐 procedure TWebModule1.WebModule1ActionPopulationAction(
源代码网推荐 Sender: TObject;
源代码网推荐 Request: TWebRequest; Response: TWebResponse;
源代码网推荐 var Handled: Boolean);
源代码网推荐
源代码网推荐 begin
源代码网推荐 // set specific values
源代码网推荐 Chart.Title.Text.Clear;
源代码网推荐 Chart.Title.Text.Add ("Population of Countries");
源代码网推荐 Chart.LeftAxis.Title.Caption := "Population";
源代码网推荐 Series.Title := "Population";
源代码网推荐 Series.PieValues.ValueSource := "Population";
源代码网推荐 end;
源代码网推荐
源代码网推荐 procedure TWebModule1.WebModule1Create(Sender: TObject);
源代码网推荐 begin
源代码网推荐 // open the database table
源代码网推荐 Table1.Open;
源代码网推荐 // create the chart
源代码网推荐 Chart := TDBChart.Create (nil);
源代码网推荐 Chart.Width := 600;
源代码网推荐 Chart.Height := 400;
源代码网推荐 Chart.AxisVisible := False;
源代码网推荐 Chart.Legend.Visible := False;
源代码网推荐 Chart.BottomAxis.Title.Caption := "Name";
源代码网推荐 // create the pie series
源代码网推荐 Series := TPieSeries.Create (Chart);
源代码网推荐 Series.ParentChart := Chart;
源代码网推荐 Series.DataSource := Table1;
源代码网推荐 Series.XLabelsSource := "Name";
源代码网推荐 Series.OtherSlice.Style := poBelowPercent;
源代码网推荐 Series.OtherSlice.Text := "Others";
源代码网推荐 Series.OtherSlice.Value := 2;
源代码网推荐 Chart.AddSeries (Series);
源代码网推荐 // create the memory bitmap
源代码网推荐 Image := TImage.Create (nil);


源代码网推荐 Image.Width := Chart.Width;
源代码网推荐 Image.Height := Chart.Height;
源代码网推荐 end;
源代码网推荐
源代码网推荐 procedure TWebModule1.WebModule1Destroy(
源代码网推荐 Sender: TObject);
源代码网推荐
源代码网推荐 begin
源代码网推荐 Chart.Free;
源代码网推荐 Series.Free;
源代码网推荐 Image.Free;
源代码网推荐 end;
源代码网推荐
源代码网推荐 procedure TWebModule1.WebModule1AfterDispatch(
源代码网推荐 Sender: TObject;
源代码网推荐 Request: TWebRequest; Response: TWebResponse;
源代码网推荐 var Handled: Boolean);
源代码网推荐
源代码网推荐 var
源代码网推荐 Jpeg: TJpegImage;
源代码网推荐 MemStr: TMemoryStream;
源代码网推荐 begin
源代码网推荐 // paint the chart on the memory bitmap
源代码网推荐 Chart.Draw (Image.Canvas, Image.BoundsRect);
源代码网推荐 // create the jpeg and copy the iamge to it
源代码网推荐 Jpeg := TJpegImage.Create;
源代码网推荐 try
源代码网推荐 Jpeg.Assign (Image.Picture.Bitmap);
源代码网推荐 MemStr := TMemoryStream.Create;
源代码网推荐 try
源代码网推荐 // save to a stream and return it
源代码网推荐 Jpeg.SaveToStream (MemStr);
源代码网推荐 MemStr.Position := 0;
源代码网推荐 Response.ContentType := "image/jpeg";
源代码网推荐 Response.ContentStream := MemStr;
源代码网推荐 Response.SendResponse;
源代码网推荐 finally


源代码网推荐 MemStr.Free;
源代码网推荐 end;
源代码网推荐 finally
源代码网推荐 Jpeg.Free;
源代码网推荐 end;
源代码网推荐 end;
源代码网推荐
源代码网推荐 end.


源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华