Multi-layer structure must not be a few TclientDataSet comprehensive analysis

xiaoxiao2021-03-06  62

Multi-layer structure must not be a few TclientDataSet comprehensive analysis

In the three-layer structure, the status of TclientDataSet is unrecivalent. Her use is very critical, this article explains her use from the following aspects, I hope to help you.

Dynamic index

Procedure TFORM1.DBGRID1TITLECLICK (Column: Tcolumn);

Begin

IF

Not column.field

Is TBLOBFIELD)

THEN

// TBLOBFIELD can not index, binary

ClientDataSet1.indexfieldNames: = column.field.fieldname;

END;

2. Implementation of the master from the table in multi-layer structure

Standby CLIENTDATASET1.PACKETRECORD is -1, all records

Set from the table clientDataSet1.packetRecord to 0, current record

3.Taggregates use

(1) AGGREGATES in the field editing

After setting Expression (Expression)

Set Active: =

True

Use dbEDit's field for the former

(2) Use aggergates attribute Add design expression test

transfer

ShowMessage (FLOATSTR (ClientDataSet1.aggRegates.count);

ShowMessage (ClientDataSet1.aggregates.Items [0] .value);

4. Don't BDE in a single layer database

Use ClientDataSet instead of table, loadFileName with ClientDataSet to load CDS

Instead of Table TableName DB or DBF

The original program transformation method:

Add a ClientDataSet, use the right-click Assign Locate Data

After Savetofile, then loadFromfile, remove Table

Set the DataSource of the original Table to ClientDataSet

The only thing to pay is: To copy midas.dll to system or current directory

5. Implementation method of briefcase of the three-layer structure

At the same time, set 1: filename (*. CDS) 2.Remote Server

6. You can assign a value for DATA (from another data set)

ClientDataSet2.data:=ClientDataSet1.data;

ClientDataSet2.Open;

or

ClientDataSet2.clonecursor (ClientDataSet1,

True);

ClientDataSet2.Open;

7. Additional data

The client requests data to the application server. If TclientDataSet

The fetchondemand property is set to

True,

The client will automatically retrieve the value of the attached packet such as the value of the blob of the blob or the contents of the hidden table as needed.

otherwise,

The client needs to explicitly call GetNextPacket to get these additional packets.

ClientDataSet's PacketRecords sets a number of records obtained at a time

8.ClientDataSet and server-side QUERY connection method

(1) SQL content is empty

ClientDataSet1.Close;

ClientDataSet1.commandtext: = Edit1.Text;

// 即 SQL content

ClientDataSet1.Open;

Filter such as: Country Like 'a%' for no application server

FILTERED =

TRUE can implement SQL functionality

(2) Parameters

If the server Query's SQL is

Select * from animalswhere

Name Like: DD

Then: Client ClientDataSet

VAR

PM: tParam;

Begin

ClientDataSet1.Close;

ClientDataSet1.ProviderName: = 'DataSetProvider1';

PM: = tParam.create

NIL);

PM.

Name: = 'DD';

Pm.DataType: = ftstring;

ClientDataSet1.Params.clear;

ClientDataSet1.Params.Addparam (PM);

ClientDataSet1.Params.Parambyname ('DD'). Asstring: = Edit1.Text;

ClientDataSet1.Open;

PM.Free;

END;

9. Update management of data

(1) SavePoint saves the current data status so that it can be restored to this state

VAR

PP: integer;

Begin

PP: = ClientDataSet1.savePoint;

ClientDataSet1.EDIt;

ClientDataSet1.fieldbyName ('Name') .sstring: = 'Old Tell';

ClientDataSet1.post;

Table1.refresh;

END;

Recovery point

ClientDataSet1.savePoint: = PP;

(2) Cancel, RevertRecord

Cancel the changes to the current record, only suitable for POST, if POST, call

RevertRecord

(3) Cancelupdate

Cancel all modifications to the database

(4) UndolastChange (Boolean), ChangeCount

Cancel the last modification, you can achieve continuous undo

Parameter

True: Cursor to Restore

FALSE: The cursor does not move in the current location

ChangeCount returns the number of times of modifying records, a record modification multiple times, return only one

But undolastchange only withdraws once

10. Well-writable Recno

Recno for TTable and Tquery is read-only, and TclientDataSet's Recno readable can be writable

ClientDataSet1.Recno: = 5; It is the fifth record as the current record

11. Data save

For Table Using POST to update data

The POST of ClientDataSet1 only updates memory data, and updates server data to use

Applyupdates (MaxerRors: Integer), he has a parameter and is allowed to make an error

The number of times, -1 indicates countless times, and it is often set to 0 when using SimpleObjectBroker, automatic fault tolerance and load balancing.

Note: I have limited level, it is inevitable that there will be a lot of guides.

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

New Post(0)