Web Application Opener - WebSnap (Nine)

zhaozj2021-02-08  221

Web Application Opener - WebSnap!

Chapter, illustration and superconduct

9-1 simple graphic display

In the previous database program we did not discuss how to deal with the blob field information, because I think this is very simple, WebSnap helps you have a lot of work, you just take the database. The action of one chapter is made, and after replacing the database with Biolife.db with a blob field, you can see graphics and renovate them. In some cases, you can change the map to a single file name due to the efficiency or the consumption of the space. At this time, we can apply TADAPTERIMAGEFIELD to handle this type of demand. Before we write this database web page, we must first understand how TadapterImageField is only available, let's use our computer web page to do the test product, please in Calc Page Add a TadapterImageField in the Adapter1.Data characteristics in Module, and set her HREF feature value:

(You must set up the WEBAPDEBUGER's PATH, please refer to the latest statement of this section)

Open Visual Page Designer Add an AdapterDisplayField to AdapterfieldGroup1, you will see the following preview picture:

The diagram is empty, this is because I am in the design mode, and the HREF set by our set is caused by the URL. Don't care about her, you can see the graphic display on the web. In addition to understanding the HREF, we can also choose to write OnGethRef to dynamically pass back HREF, or write OnGetImage to use TFileStream to read image file. After passing back to ImageField. When there is a need for a diagram, we can write the ONUPLOADFILE event to upload the map archive that you should upload, you should have to think about how to solve the file library map of the file name. It's just as easy as you think, because we only save the text file name, so you can't use TDataSetImageField, there is no online event to use unless we handle the client sent by the client, this is too trouble, this is too trouble, Then how should we do it? Well! Good problem, we will deal with this problem in the next section.

9-2 Imperial Processing

To solve the problem described above, we can add a TadapterImageField in TDataSetadapter, followed by her back to DataSetadapter Fields, and listening is very simple, like it is also very reasonable. Oh! The thing is still not finished, this is the TadapterImagefield, which is self-added. In addition to the TDataSetAdapter, she can have a relationship with TDataSetadapter, which means that the TDataSetAdapter is moving the record indicator, and our TadapterImageField can be like a mountain. In order to solve this problem, we have to use the online online characteristics, forced WebSnap to move her, TDataSetadapter and TadpterImageField procedures are as follows:

function TImageDB.GetAppPath: string; var FN: array [0..255] of char; begin GetModuleFileName (hInstance, FN, SizeOf (FN)); Result: = ExtractFileDir (FN); end; procedure TImageDB.AdaptPictureNameGetImage (Sender: TObject; Params: TStrings; var MimeType: String; var Image: TStream; var Owned: Boolean); var AppPath: string; sImagePos: string; begin AppPath: = GetAppPath; sImagePos: = params.Values ​​[ 'PICTURE_NAME']; Image : = TFileStream.Create (AppPath '/ Images /' sImagePos, fmOpenRead); end; procedure TImageDB.AdaptPictureNameUploadFile (Sender: TObject; aFile: TAbstractWebRequestFile); var fs: TFileStream; AppPath: string; FileExt: string; begin if aFile .Contettype = 'image / jpg' Then fileExt: = '. Jpg' else if Afile.contentType = 'image / pjpeg' Then fileExt: = '. Jpg' else if Afile.contentType = 'image / bmp' Then FileExt: = '.bmp' else = 'image / gif' Then fileext: = '. gif' else fileext: = '; if FileExt <> '' Then begin fs: = TFileStream.Create (AppPath '/ Images /' AdaptName.ActionValue.Values ​​[0] FileExt, fmCreate); fs.CopyFrom (AFile.Stream, 0); DataSetAdapter1.DataSet.FieldByName ( ' PICTURE '.) AsString: = AdaptName.ActionValue.Values ​​[0] FileExt; fs.Free; end; end; procedure TImageDB.AdaptPictureNameGetParams (Sender: TObject; Params: TStrings); begin Params.Add (' PICTURE_NAME = ' AdaptPicture.Value); end; procedure timagedb.adaptPicturenameValidateFile (Sender: Tobject)

AFile: TAbstractWebRequestFile); begin if (AFile.ContentType <> 'image / jpg') and (AFile.ContentType <> 'image / pjpeg') and (AFile.ContentType <> 'image / bmp') and (AFile.ContentType <> image / gif ') Then Raise Eadapterexception.create (' Unknown Graphic Format "; END; Let's see the OnGetImage event first, we read the diagram after reading the diagram, the file is from The paramese parameter is taken, then this parameter is put in? Do you see the online portrams? We are letting the parameters here, see the following HTML:

/EXAM_1_TESTSVR.MYSIMPLEWEB/?Picture_name=test4.bmp&__id=imagedb.datasetadapter1.picturename "alt =">>

We use this parameter to make WebSnap determined AdapterImageField must follow DataSetAdapter, you can take this movement, change it straight from AdapterPicture, you will solve what I think. In this program, we also use the validatefile event to discriminate the file format. If the file format does not match, we will trigger an exception, this exception's message will be encapsulated in Adapter.erro, then we can display an error in the web page. Message, this program I use a new Adapter and an adapterfield and add the following Script code code in HTML:

<% = adapter1.ErrorMsg.Value%>

Take the value of the above:

procedure TEditImageDB.AdaptErrorGetValue (Sender: TObject; var Value: Variant); begin if ImageDB.DataSetAdapter1.Errors.ErrorCount> 0 then Value: = 'error:' ImageDB.DataSetAdapter1.Errors.Errors [0] .ErrorText; end;

Detailed prices You can find it in the image of the model. To make WebAppdebugers, I will find this path under / Images. We must add this path to WebAppDebugers. Please open WebAppDebuger's Server | Options options and add your path: This chapter

Although I use BDE in this article to handle the database, I recommend you to use other Driver because BDE has session and some restrictions unless you use Datasnap, otherwise the development of the website may not withstate too many users. I recommend that you use ADO or dbexpress to replace BDE, or use DataSnap directly, you should be able to find it in other books, I will not say more, in the OnGetImage event, we read the graphic Back to the client, this is what I specially written in order to let you know the use of the OnGetImgae event. In fact, in practice, you should use another online antef to return to the URL of the graphic, which can reduce the burden on Web Server, especially the program There are two servers with graphics, which can make your program response speed faster. If you have the imageProducer that you have tried Delphi6, you should know how to use the picture to make a juncture, I will discuss her under the next.

转载请注明原文地址:https://www.9cbs.com/read-3110.html

New Post(0)