Platoo FReport ComponentsDatabase management


This chapter describes how to write database applications with FR components.

Delphi declaration

C++ declaration

The work of the HTTP database application can be described in the following stages:

1. The server receives some request parameters and reads the relevant data from the database.

2. On the basis of the read data the server creates a HTML document and sends it to the client.

3. The client views/changes the data and sends it back to the server together with a request to process it.

4. The server changes the data in accordance with the client's request.

A major difference between the HTTP application and desktop or RDBMS server application is that the HTTP server is not aware of the client's previous activities, every request made to the server is independent, as desktop and RDBMS applications use cursors (as the TTable component) to maintain the connection between the application and the database. Thus, to complete step 3 it must be possible to identify the database entry that the user is processing. For that the TFRRecordKey component is used. If the HTML document includes data from several database entries, the server must identify all the entries separately, and therefore the TFRRecordKey is needed for each entry. This means that if TFRBand or TFRTableBand are used to add repeated entries to the document, the TFRRecordKey must be on the same band, in this case its data will also be entered repeatedly.

In case of FR components the TFRDataSource is used to process the data and manage the data exchange between the database and application.

To manage the TFRDataSource activity, the relevant information is included in the URL PATH:

If the URL is:

then on the basis of the "first" part it is decided which TISAPIActionItem processes the request.

The "second" part is the name of the TFRDataSource component that has to process the data and the "third" part determines the action to be carried out with the data.

If the "second" part is missing, the TFReport component will choose the TFRDataSource component according to its DataSource property. If the "third" part is missing, the TFRDataSource action will be chosen according to its DefaultAction property.

The data field values are returned from the client to the server according to HTTP protocol.

The usual action related to databases like Insert, Delete, Edit, Post, Cancel, Next, Prior are inherent in the TFRDataSource. In addition to these, the user may define own application-specific actions by using the TFRDataSource.CustomActions property. In this case the action must be realised in the OnRecordDataAction event. This event is called once for every entry received from the client.

In order for the client to activate the DataAction, the HTML document must include relevant elements. Every visible element has ActionDataSource and FRDAction properties for this reason. If these properties have been set, relevant ONCLICK events will be generated for the visible element which will send the relevant requests to the server.

NB! As data exchange between the client and server is carried out according to HTTP protocol using the POST method, such elements together with all the elements containing data must be included in the TFRForm component.

The data in the database entries can be added to the HTML document by using different components derived from FRInput. To do that, their DataSource and FieldName properties must be set. If there is a need to save the data received from the client in the database, for instance to realise Edit or Insert actions, the AutoName property of the relevant inputs must be set to true. In this case names are generated for them which enable TFRDataSource to write the data received from the client into the correct fields.

The data received from the client that corresponds to the database fields is gathered by TFRDataSource into the TFRInputParams object that can be accessed through TFRDataSource.InputParams property where there is one TFRInputParamItem for each database line received. During OnRecordDataAction event the TFRInputParamItem corresponding to current entry is accessible through the TFRDataSource.InputParams method CurrentItem . The DataValues property of the TFRInputParamItem object includes the datafield values received from the user in the form Name=Value, and the KeyValues property includes the values of the fields used to identify the record in the form Name=Value. In both cases Name represents the name of the corresponding field. To read the values use the Values[Name] property of the TStrings class.

In addition to actual fields included in the database, fictional fields can be added by using TFRDataSource. The data and inputs corresponding to such fields are added to every data record in the generated HTML document similarly to ordinary database fields, and the data entered by the user in these fields are returned to the server similarly to ordinary data. To calculate the initial values for these fields during the the generation of the HTML document, the OnGetInputValue event handler must be realised; and to process the data entered into these fields by the client, the OnRecordDataAction must be realised.

To open and close the database queries, the TFRDataSource OnPrepare and OnUnprepare events may be used.

The request parameters received from the users are available by using TFReport ReportParamAs*** methods. If requests with similar parameters have to be opened repeatedly, for example if the data is sent to the client in groups, see Grouping records or if according to the same request a diagram has to be drawn dynamically by using TFRDynamicImage then the report parameters can be added to the HTML document to be generated and thus, make them available for the server while processing the next request. Therefore, the names of the necessary parameters must be listed in the TFReport.ParamNames property, and a component created by TFRInput such as TFRHidden , setting its ReportParam and AutoName property.

TFRDataSource can add several empty rows to the HTML form simultaneously with the help of which the client may enter several new records in the table. In order to do that, the InsNewRecords must be set for the desired number of new records. Every time the user activates the Post action, the new records including the entered data are saved in the database and new empty records are added to the form that is returned to the user.

In addition to databases, TFRDataSource enables also to process other data that can be presented as records and fields. In such case all the events necessary for data processing must be realised.