Internet/intranet in the 90 's may be the most popular computer terminology, whether people in the computer industry or people outside the computer, will use internet/intranet, some information, some publicity themselves and the company, There are even a lot of things that have never been thought of using the Internet and are now being solved using the Internet,
For example, some program-controlled digital computer maintenance using the Internet to solve. In all of these applications, the development of web-based applications is a basic point, but how do you develop a Web server program?
Delphi 3 is a visual, object-oriented, and highly efficient rapid application development tool (RAD) launched by Borland in 1997, providing a wide range of the latest features, such as developing com/dcom, one-step development of ActiveX objects, multi-tier database application Midas, And the use of Delphi 3 to develop web-based server programs, such as isapi/nsapi,win-cgi,cgi programs are very convenient.
Using Delphi 3 to develop a Web server program is very simple and convenient because web Module is provided in Delphi
WebApplication
Twebrequest
Twebresponse
Tpageproducer and so on a large number of objects for use. And because Delphi powerful database development ability, make Web server program development is icing on the cake. In this article the main discussion of the General Web server program development, I hope to give you a useful role.
General Web server returns information that is based on HTML text flow and image streams, such as JPEG and GIF. The way to return the text stream is to use twebresponse.content, which is a routine in the demos of Delphi 3, but how do you return the image?
The way to return images is to use the Twebresponse.contentstream and Tjpegimage classes. The implementation is as follows, for example, you have three pictures that you want to randomly display when someone visits your home page, and you have the following HTML statement on your home page:, then the default twebactiveitem for your Web server is as follows:
var
Jpg: TJpegImage;
S: TMemoryStream;
I: Integer;
Begin
Randomize;
I:= Random(3);
Jpg := TJpegImage.Create;
try
Jpg.LoadFromFile('C:WebShareScriptstest'+IntToStr(I)+'.Jpg');
S := TMemoryStream.Create;
try
Jpg.SaveToStream(S);
S.Position := 0;
Response.ContentType := 'image/jpeg';
Response.ContentStream := S;
Response.SendResponse;
finally
S.Free;
end;
finally
Jpg.Free;
end;
end;
Because the Tjpegimage class is used, the inclusion of the JPEG file must be added to the uses.