How to Design tdxmemdata for memory controls

Source: Internet
Author: User

The tdxmemdata control can store the dataset database in the memory and display it on tdxdbgrid. The value of the current cursor is obtained through dxmdt1.fieldbyname ('field'). value. Use while to traverse the values in the entire dataset. In this way, you can first operate data in the memory and then submit the data to the database using SQL statements. Generally, you can add, delete, and modify an operation on a record. Internal operations can be implemented as follows: the add, delete, modify, and delete buttons only operate on data in the memory. They are submitted to the database only when the button is saved. This facilitates data processing.

Sample Code of the tdxmemdata application:

Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, DB, ADODB, dxexedtr, dxdbtlcl, dxgrclms, dxdbctrl,
Dxdbgrid, dxtl, dxcn.pdf, dxmdaset, grids, dbgrids;

Type
Tform1 = Class (tform)
Qry1: tadoquery;
Con1: tadoconnection;
Mmo1: tmemo;
Btn1: tbutton;
Dxmdt1: tdxmemdata;
Dxdbgrd1: tdxdbgrid;
Ds1: tdatasource;
Intgrflddxmdt1orderid: tintegerfield;
Intgrflddxmdt1custid: tintegerfield;
Intgrflddxmdt1empid: tintegerfield;
Dtflddxmdt1orderdate: tdatefield;
Strngflddxmdt1shipaddress: tstringfield;
Dxdbgrdclmndxdbgrd1recid: tdxdbgridcolumn;
Dxdbgrdmskclmndxdbgrd1orderid: tdxdbgridmaskcolumn;
Dxdbgrdmskclmndxdbgrd1custid: tdxdbgridmaskcolumn;
Dxdbgrdmskclmndxdbgrd1empid: tdxdbgridmaskcolumn;
Dxdbgrdtclmndxdbgrd1orderdate: tdxdbgriddatecolumn;
Dxdbgrdmskclmndxdbgrd1shipaddress: tdxdbgridmaskcolumn;
Btn2: tbutton;
Dbgrd1: TDBGrid;
Btn3: tbutton;
Procedure btn1click (Sender: tobject );
Procedure btn2click (Sender: tobject );
Procedure btn3click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation
{$ R *. DFM}

Procedure tform1.btn1click (Sender: tobject );
VaR
I: integer;
Begin
I: = 1;
Qry1.connection: = con1;
Qry1. SQL. Clear;
Qry1. SQL. Add ('select Top 12 orderid, custid, empid, orderdate, shipaddress from tsqlfundamentals2008.sales. Orders ');
Qry1.open;
Qry1.first;
While not qry1.eof do
Begin
Dxmdt1.append; // Add the read value from the data to the memory.
Dxmdt1.fieldbyname ('recid'). asinteger: = (I + 1 );
Dxmdt1.fieldbyname ('orderid'). asinteger: = strtoint (qry1.fieldbyname ('orderid'). asstring );
Dxmdt1.fieldbyname ('custid'). asinteger: = strtoint (qry1.fieldbyname ('custid'). asstring );
Dxmdt1.fieldbyname ('empty'). asinteger: = strtoint (qry1.fieldbyname ('empty'). asstring );
Dxmdt1.fieldbyname ('orderdate'). asdatetime: = strtodate (qry1.fieldbyname ('orderdate'). asstring );
Dxmdt1.fieldbyname ('shipaddress'). asstring: = qry1.fieldbyname ('shipaddress'). asstring;
Mmo1.lines. Add (qry1.fieldbyname ('orderdate'). asstring );
Qry1.next;
INC (I );
End;
Qry1.close;
End;

Procedure tform1.btn2click (Sender: tobject );
Begin
Dxmdt1.first;
While not dxmdt1.eof do
Begin
If (dxmdt1.fieldbyname ('orderid'). asinteger = 10249) or (dxmdt1.fieldbyname ('orderid'). asinteger = 10250) then
Begin
Dxmdt1.edit; // you need to set it to the edit mode first.
Dxmdt1.fieldbyname ('shipaddress'). asstring: = 'zheng Zhou ';
End;
Dxmdt1.next;
End;
Dxmdt1.edit;
Dxmdt1.post;
Dxmdt1.first;
End;
Procedure tform1.btn3click (Sender: tobject );
Begin

End;

End.

 

How to Design tdxmemdata for memory controls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.