Web Application Opener - WebSnap (3)

zhaozj2021-02-08  271

Web Application Opener - WebSnap!

Seal, WebSnap and materials

3-1 basic concept

WebSnap has a lot of WebBroker InternetExpress, which is more than the WebBroker InternetExpress before the material, and uses WebSnap to issue a material library network page. It can be said to be a simple and pleasant thing. Before we start writing the material library program, let me first let me first solve the WebSNAP, where the communication material library and the web page are written.

TDataSetadapter components are like the Adapter meaning they discussed in Section 1, TDataSetAdapter is the Adapter of DataSet. We can use the functions of TDataSetadapter to operate on the DataSet component in her internal, then do you design? Why don't you use DataSet? Answer us to recall the computer example of the previous section, Adapter is not just for supply Delphi program, she also outputs the Wrapper object allows us to use her in Script, which is what DataSet can't do. You can also add an AdapterfieldGroup or AdapterGrid in TadapterPageProducer, set TDataSetadapter or simple adapter to display or remember the information, they don't care what you have set to her is Adapter or TDataSetAdapter or you write. Adapter, this greatly enhances the reuse of the program code. For example, you can write an adapter to output a list of files under a directory, and use adaptergrid to display them. Is this a great?

TDataSetAdapterfield components and TDataSetadapter, TDataSetAdapterfield is the Adapter of Tfield. After tits, TDataSetadapter and TDataSetadapterfield is a complete DataSet Adapter, we can use TDataSetAdapter to search for materials, or use TDataSetAdapterfield to display and change information. Let us use them to write a web page that can be displayed with a compilation.

3-2 Simple material library network page

As the example of the previous section, we add a web page that describes the information. Please open new items dialog and switch to WebSNAP Page:

Select WebSnap Data Module here, which is often used to store Database Components, or some auxiliary non-visual components. After execution, we can set some of this Data Module, we explain before the CACHING option, let us see the Creation option, which has appeared in Page Module, just at the time, I didn't explain her, basically this option will Impact Module's establishment behavior, the preset is on Demand, which does not establish this module when the program is started, but it will establish this module when she is used. What is the suggesting time?

1. When the object in Module is used by the object of the Activate Module, the example will be set to another Module to a TDataSetAdapter element. 2. When the Ming's Ming is enabled by the Factroy Method, the constructive letter refers to the following:

Function WebDataModule1: TwebDataModule1;

Begin

Result: = twebdataModule1 (

WebContext.FindModuleClass (TwebDataModule1);

END;

Timer 1 is made by Form Load System, and the other will like the type of components in Form2 in Form2, just in Form2, us use the domain variable, which we use Factroy Method. In addition to the ON Demand option, there is another always option to choose from, this option will be established immediately when the module is executed, which can be used on module with high usage, such as Application Module is using this option. Because regardless of the user's request is the web page or that an action, Websnap must start Application Module to distribute these requirements. If you re-establish it, you will waste some time. Because this time is high, you can consider the efficiency of shelling her to Always, with a memory.

Back to the model, please put the three components of Database, Table, Session in Web Data Module, and set their characteristics:

Then please add all of the Fields in Table.

Please change the name of Module to WDMDATA, and we must add a Page Module if you archive, select AdapterPageProducer as this pageproducer, and add Page Name to Grid, then join a TDataSetAdapter to this Page Module in order to Using the Table component in WDMDATA, we must be Uses Udmdata.

After you can return to the DataSetAdapter component to set your characteristic value.

After setting it, please double according to the Data "of DataSetAdapter to add all the columns.

Next, I have to set the display picture of the web page, please open the Visual Page Designer window, add an AdapterForm component, and add an AdapterGrid component in the inside.

Then set the Adaptergrid.Adapter characteristic value to DataSetAdapter.

After you finish, you can see the following pictures, if you don't have a display, you can be your table, please return to Data Module to open Table.

Well! This picture is a bit ugly, we can use CSS to beautify her, please enter the following CSS commands in the STYLES characteristic value of AdapterPageProducer:

.Custcol {width: 70;} .companycol {width: 220;} .addr2col {width: 60;} .countrycol {width: 140;} .citycol {width: 90;}

You can choose the CSS Style you need to choose in the Stylerule of AdapterDisplayField.

In the WEBSNAP network page designation, it relies on CSS in the process, the original because the CSS does not but can simplify the network pages, and can make the style of the entire network station, because this good CSS book is very important. Let's go back to the example, basically we have completed a web page that can be displayed, then we also build a web page for the program, add a Page Module, select AdapterPageProducer, and set the name to Edit, After completing, add a TDataSetAdapter component to this module, followed by the Grid Module, and add DATAMODULE and add all the fields. Then please open the Visual Page Designer to add an AdapterForm component and add an adapterfieldgroup component in the inside:

Then set the adapterfieldgroup.Adapter characteristic to DataSetAdapter. By the web page to which we want to make a compilation, please set AdapterMode as Edit.

If you have no questions, you should have to see a watched web page.

We also need a press to make a reputable material to the material library, please press the right button on the AdapterForm component and set DisplayComponent to AdapterfieldGroup.

After you finish, you will see a row of exercises.

In this example, we only need Apply to press New, please press the right button on adaptercommandgroup to select the Add Command option to add an apply button

Here we have completed a web page for programming, then we hope to add a web page to this renovated on the Grid page, so we return to Grid Module to open the Visual Page Designer window, in Press Right click on the AdapterGrid component to add an AdapterCommandColumn component.

After you finish, you should see how many press is displayed in the rear of each material. In this example, we only need to edit pressing the New button, please press the right button on AdapterCommandColumn to select the new EDIT button.

After you finish, you can see this button at the last column of each material, you can also adjust her display in the window of the Move Up on the window.

However, we have to set up the use of this to press this button, and we only need her to connect to Edit Page, we can use the settings of the PageName to achieve this purpose.

We hope that it can make the user pressing the Apply button in the editing network page, which can be automatically returned to the GRID network page, which can be completed by the PageName characteristic value of the setting apply button.

OK! Large effort, follow the programs to see our achievements!

Unfortunately, when you fix the information, press Apply to press New Yeah, you will get this error:

This is because WebSNAP uses Variant to compare the information. This action may trigger the exception to the type conversion, and we are executing the program in the DEBUGER state, so the exception is intercepted by Delphi, this does not affect the information. Save action, because of the complete handling of the WebSNAP, when the designer conversion exception occurs, the same value has been changed, please press F9 to continue execution. In the webpage program, you usually encounter some difficulties. For example, the pre-verification or format is limited, and these problems are currently not much support in WebSNAP, such as no ready-made components, can be dismantled into three Enter the field, or you cannot use Client-Side Script to verify the empty field. Although you can use PageProducer to add manual adjustment Script to achieve this effect, but this is not enough. These issues I will submit some solutions in the chapters of the rear. Let us continue to strengthen our examples, we hope to let users use ComboBox ways to select the country, to achieve this effect, we must join a Country database in Data Module, followed by adding a TDataSetValuelist component in Edit Module database.

The valuelist characteristic value of the Country column in DataSetadapter is then set.

After completing the Visual Page Designer, you can see that Country has become a ComboBox.

Very simple? If your information is not the database, you can change TDataSetValuelist to TStringsValuelist so you can customize Items in ComboBox. There are many HTML Control in WebSnap to choose, you can try it yourself. Try.

3-3, material search and wrong handling

Before I end this chapter, let us have an exercise question, can you add an edit and a button on the Grid, let the user press the button to the EDIT web page? Combined with the computer and The knowledge in this section should be enough for you to do this. As for the sort of search materials, I can use two modes, one is to use the use of Dataset, the other is the Locate Method using TDataSetAdapter, I recommend you use the latter:

procedure TGrid.QueryExecute (Sender: TObject; Params: TStrings); var LocateParams: TLocateParams; begin // use dataset //wdmData.Table1.Open; //wdmData.Table1.Locate ( 'CustNo', AdaptEnterCustNo.ActionValue.Values ​​[ 0], []); // use dataset Adapter LocateParams: = dsAdaptCust.LocateParamsList.Add; LocateParams.AddParam ( 'CustNo', AdaptEnterCustNo.ActionValue.Values ​​[0]); LocateParams.AdapterName: = dsAdaptCust.Name; dsAdaptCust. Locate; END; How do you handle when the information entered in the database? You have two options, one is to trigger an exception, WebSnap will display exception to the web page:

If not dsadaptcust.locate the raise exception.create ('information is not available!');

Another method is to set the Adapter.Errors characteristic value to indicate the failure, then set the ErrorPageName in ActionButton to demonstrate the specific network page:

If not dsadaptcust.locate kilror ('information is not available);

In the model case in the archive, you can choose from the needs of your needs.

3-4 AdapterErrorList components

We can also use the AdaptererrorList components to display the wrong information to the user, please open the Visual Page Designer in this page module and add an AdapterrRroust component in Adapterform1:

Connect the Move Up to move this component to AdapterForm's top layer:

Then set her adapter as adapter1.

You can test the results in the test. Before doing test, please modify the Query Action's Onexecute event program:

procedure TGrid.QueryExecute (Sender: TObject; Params: TStrings); var LocateParams: TLocateParams; begin // use dataset {wdmData.Table1.Open; wdmData.Table1.Locate ( 'CustNo', AdaptEnterCustNo.ActionValue.Values ​​[0], []) then} // use dataset Adapter LocateParams: = dsaCust.LocateParamsList.Add; LocateParams.AddParam ( 'CustNo', AdaptEnterCustNo.ActionValue.Values ​​[0]); LocateParams.AdapterName: = dsaCust.Name; // use exception {If not dsacust.locate the Raise Exception.create ('Information does not exist!');} // use errorlist if not dsacust.locate the adapter1.erroS.Adderror ('Information does not exist!'); End; when you enter After an incorrect value, you will get the following display screen.

If you want to show the wrong mistake by another web page, you can set this Action's error to the name of the error page, and add AdapterForm-AdaptererrorList in the Error Page network page, and then set AdaptererrorList to adapter1.

3-5 WebSnap in WebSnap

In this section, I discussed why in WebSNAP, if I changed the online page, and the wrong mistake and the TDataSetAdapter. You should note that I have used two different TDataSetadapter to connect the same Dataset, which is the purpose of which I can modify the EDIT web page to make the EDIT web page. If your purpose is just to let the user use only Apply functions, then you can put TDataSetAdapter in WebDataModule or Grid Page Module, and discriminate that the user in the Edit Module's BeforeDispatcher event is directly entering this web page or Enter the action in the Grid Page Module. If it is directly entering, the user will guide the GRID website:

uses WebReq, ​​WebCntxt, WebFact, Variants, udmData, AdaptReq, SiteComp; function Edit: TEdit; begin Result: = TEdit (WebContext.FindModuleClass (TEdit)); end; procedure TEdit.WebPageModuleBeforeDispatchPage (Sender: TObject; const PageName: String; var Handled: Boolean); procedure RedirectToGrid; var Intf1: IPageDispatcher; AppModule: TObject; GetAppService: IGetWebAppServices; AppService: IWebAppServices; AppComponents: IGetWebAppComponents; begin if Supports (WebContext.FindApplicationModule (Self), IGetWebAppServices, GetAppService) then begin AppService: = GetAppService.GetWebAppServices; if Supports (AppService, IGetWebAppComponents, AppComponents) then begin Intf1: = AppComponents.GetPageDispatcher; Intf1.DispatchPageName ( 'Grid', Response, [dpPublished]); Handled: = True; end; end; end; var Intf : IACTIONFIELDVALUES; Begi n if Supports (WebContext.AdapterRequest, IActionFieldValues, Intf) then begin if VarIsEmpty (Intf.ValueOfField ( 'EnterCustNo')) then RedirectToGrid; end else RedirectToGrid; end; end; or you can also use the two WebDisp Unit The function of the function is turned:

function DispatchPageName (const APageName: string; AResponse: TWebResponse; AFlags: TDispatchPageFlags): Boolean; function RedirectToPageName (const APageName: string; AParams: TStrings; AResponse: TWebResponse; AFlags: TDispatchPageFlags): Boolean;

Both of these two functions can be re-directed to the web page. When the most obvious difference is when using the RedirectTopageName, we can pass the parameter value to the DEFAULTAACTION of the target, and then make the correct response by the parameter value. That is to say she triggers the DefaultAction event in the target page module. DISPATCHPAGENAME, there is no more than the moderate mode, RedirectTopageName is an external movement, this means that she is turning by a browser, and DispatchPageName is an internal turn. When you need a single pure turn, you can use DISPATCHPAGENAME, when you need to turn and touch the defaultAction in this page module, you can select RedirectTopageName. In addition, if you turn to the web page, it is said that it is a URL, then you can use Saferedirect, this one can send cookies to the target network page after the web page. This chapter

If you are talking about the first quarter, webSNAP to issue the network page material library is not difficult. The most important thing is that she has continued to develop the subscription of the priority before us, so that our learning curve is more stable. Of course! This chapter is just a beginning, and we will continue to introduce their topics.

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

New Post(0)