Multi-Tier structural program development basic tutorial (1)

zhaozj2021-02-16  62

Multi-Tier architecture program development based tutorial (I.1) Author: z33

In view of the students who have just entered Delphi, the Multi-Tier structure programming speaking to the teacher is not very understanding, so I wrote the following tutorial, give me the best classmates, I hope this tutorial can help the students better. Learning Delphi, don't fall, I hope that I have a deeper understanding of Delphi by writing a study experience.

I don't want to say more, I don't want to say more, I only write this implementation process. First, first write the application server, the role of this server is to connect the database and client, and the bridge before the client and the database server (temporarily called it). 1. Create a new project, File - New - Application. 2. Place a new project to put a multi-storey "remote data template" (Chinese I think it should be called this), File - New - Other -multitier - Remote Data Module - Click OK. 3, the next step, there will be a dialog box, the name is in a good time OK. In the above picture, CoClass Name is the name of this program, called COM name, this name is best to make a meaningful name, because the time you need to connect to this server according to this name. For example: Multi_Test (meaning multi-layer test) or x_test, please remember ~ and cool! . {The following gray word This paragraph does not need to understand the following instancing selection server processing thread mode, now Multiple Instance means how far clients can share a thread application server. And Single Instance is a multi-to-many processing method, that is, a client corresponding to a thread application. When multiple clients, the server will also open the same thread as much as the client, the benefits are relatively independent of each thread, no It will affect each other, but relatively compare resources. And INTERNAL is a COM program (DLL file format) that creates an in-process, which is relatively small, and I understand that it is needed to be compatible with other objects. This is my understanding, and there are different opinions welcome to discuss. The last threading model is used in the multi-task mode of the In-Process COM program, too much, too lazy, everyone reads the book. } 4, continue! Drag a table1 component to FORM1, set the table1's DatabaseName to DBDemos, Table Name is Customer.db. (This is the foundation, I don't have much to talk, I don't know how to learn before.) Drag a DataSetProvider1 component (don't ask me in which column of my ClinentDataSet component, you have been looking!), And set its DataSet property to Table1. Here the DataSetProvider group is an interface to which the data set is provided to the client. DataSetProvider, the DataSet property is what is set to set its dataset, here pointing to Table1. To make this, our server is completed, followed by run, the purpose of run is to let the server register in the system. (In addition, you can also add a Label tab to Form1, logo, as shown below: 5, save the project. Second, write a client application 1, create a new project. File - New - Application 2, drag a TDCOMCONNECTION control to Form1 On (or not that sentence, don't ask me where it is).

Setting its computername property into 127.0.0.1, here you want to explain: computername This property is the server you want to connect, fill in 127.0.0.1 is your own machine, because you want to debug on your own machine. Of course, if you want to connect to another machine, of course, the premise is that other machines have an Application Server that has been doing and registered. It is simple to say that the application server we do above. For example, if you want to have an Application Server that has been made and run on my machine, then my machine name is C2109, you can fill in my C2109 in ComputerName, you can connect to me. The machine is operated. Of course, you can also fill in the IP address, because some computer names may cause errors, such as "Coke Cat" computer name, it seems to be "Coke Cat", Chinese name, do you dare to use? I don't dare, or connect it with an IP. Is it? Then, then set the properties of ServerName, this property you will find the name you have created, forgot? Go back and see. 3, drag a TclientDataSet control, set the RemoteServer property to DCOMCONNECTION1, and then select the Provider belong to DataSetProvider1. Note that when you click the Provider property, the application server will be started. (Do not turn off the window of the server, keep it, or you will be wrong!) As shown below: 4, drag a TDataSource and TDBGRID, TDBNAVIGATOR to FORM1, set the DataSource1's DataSet property to: ClientDataSet1, and put dBGrid1 The Datasource property of DBNAVigator1 is set to: DataSource1, and finally set the clientDataSet1's Active property to: True, activation. 5, save the project, and run, so this simple mulit-tier is already fine, have you learned? The final effect is as follows: this section, in fact, I should talk about ActionList's Standard Action to implement DBNAVigator's work, because this section does not really realize its clientDataSet ApplyUpdates, that is, Submitted data, but now I should sleep, so the remaining left to the next section. If you think that I have a problem, which place is wrong, welcome to find me discussion, everyone study together, and finally. . . . I hope everyone can understand. Oh ~ Yes, there is a multi-storey database unusual processing, although the teacher demonstrates it, I still don't understand, I want to create a new Reconcile Error Dialog, which is new, I don't have any value, and not Rational, wait for me to study research. :)

This source program download | Really realized Applyupdates source program download

Multi-Tier architecture program development based tutorial (a .2) Author: z33

Only Multi-Tier's connection, in fact, the previous section should talk about this, but because of the limited time, it is divided into two parts, huh, huh ~. Because the Multi-Tier structure is different from the ordinary single machine, we can't write data to the database with a single way. This section tells the data operation on the multi-layer structure. We have to use the program on the first section, this time you have to put some functions of data operations. 1. First, we don't have to use DBNAVigator1, and use the ActionList control to implement the data operation, we also need to build 5 ammonium buttons, and implement these features through the ActionList's Standard Action. 1. Place 5 ammonium buttons to Form1, then drag the last control of the Standard control bar: ActionList control, this control is a control that helps us quickly complete the ammonity function, as shown in the figure: Let's implement it: a. Double click ActionList control, an editing form1.actionList1 window, right click on the left half blank point, then select "New Standard Action ..." item, as shown: b. A list of Stand Action, we found DataSet items , Select all children in this, then click OK, as shown: c. Set the action attribute of each button to the corresponding Action preset function. As follows:

Ammonium buttons

Action attribute

Implement function

Button1

DataSetInsert1

Insert a data

Button2

DataSetEdit1

Edit the current record

Button3

DataSetDelete1

Delete the current record

Button4

Datasetcancel1

Cancel the current operation

Button5

Not set up

Write a modified database (CAPTION: = Write)

d. The name of the CAPTION of each ammonium button is functional. As shown in the figure: E. Double-click the "Write" button, write to the following bold statement to make changes to the database: Procedure TFORM1.BUTTON5CLICK (Sender: TOBJECT); Begin ClientDataSet1.ApplyUpdates (0); showMessage Successfully written in the database '); END; where applyupdates is a clientDataSet, the function is to submit client data to the server side, and 0 in parentheses indicate that the maximum value of the error is 0, that is, it is not allowed to have an error.

It's time to get here, I should wash and sleep ~~, this time I didn't talk about it, the main thing is the clientDataSet1.Applyupdates (0) that writes an ammonium button; this statement can be implemented to the database submit data. The next section tells the Multi-Tier's Transaction (transaction), server response mechanism, and error handling mechanism.

Source program download

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

New Post(0)