Apply DDX and RFX in ODBC

xiaoxiao2021-03-06  52

Apply In ODBC class library in DDX and RFX MFC in ODBC

---- MFC neutralization provides five basic categories for ODBC database programming. These classes are encapsulated with ODBC's API calls, enabling users to use ODBC to complete different types of database programming work, such as different types of data library files such as FoxPro, DBASE, or Sybase, avoiding complex internal structures of various types of data library files. These five basic classes are:

The CDatabase class object representation is connected to the data source. User is based on this connection to realize the operation of the data source.

The CRecordset class object indicates a set of records selected from the data source. This pair makes the user to complete the scroll between records, update records, and perform operations such as filtration.

The CRecordView class pair is connected to a CRecordset class pair, which is viewed for the recordset. It is the interface of data library operation.

The CfieldExchange class supports the field transform process of the database, that is, the RFX mechanism.

The CDBEXCEPTION class is completely related to data library class operation. The user can distinguish the existing wrong cause or show the corresponding text information in accordance with the value of the public member variable. ---- I have used the AppWizard in the VC to generate a simple example program for use:

---- 1. Select [New] in [File], select the document type to [MFC AppWizard (EXE)] in the pop-up dialog box. Key to enter the document name in [Project Name], such as: TestoDBC, point the [OK] button.

---- 2. Select [SINGLE Document] in the program class, tap the [Next] button.

---- 3. Choose [Database View With File Support] in Database Support, Tap the [Data Source] button to enter the Database Selection Dialog box.

---- 4. Select [ODBC] in [DataSource], then select [Visual FoxPro Tables] in the drop-down list. [RecordSet Type] is set to [Snapshot]. Tap the [OK] button to select the data library source document: Test.dbf.

---- 5. After the data library source file is selected, the connections are connected to [Next], and the source file required to generate the program.

---- This time is generated in all kinds and its objects:

Caboutdlg

CMAINFRAME

CTestodBCAPP

CTestodbcdoc

CTestodbcset

CTestodbcView RFX Summary ---- RFX is the abbreviation of Record Field Exchange, meaning that the record field data is exchanged. It has established a relationship between the Data Set and the Data Source hidden in the back desk, so that the user can perform the operation of the data source through the operation of this record. A series of RFX call functions are provided in the MFC. These functions can be exchanged between the records and data sources, which can be exchanged between the records and data sources. These functions are: function data type RFX_BOOL BOOLRFX_BYTE BYTERFX_BINARY CBYTEARRFX_DOUBLE DOUBLERFX_SINGLE FLOATRFX_INT Intrfx_long LonigRFX_LONGBINARY ClongbinaryRFX_Text CStringRFX_DATE CTIME

---- They have three parameters (one will have four or five):

A pointer pointing to the CfieldExchange class pair;

A field name in the source;

Variable name with this field. ---- When using AppWizard to generate a code, the program will automatically select the appropriate function to match the data type.

---- The core of the record field data is the virtual function DOFIELDEXCHANGE in the CRecordset class. The RFX function is called in DofieldExchange. It provides a pointer to the RFX function to the CFIELDEXCHANGE object, whose prototype is:

---- Virtual Void DofieldExchange (CFIELDEXCHANG? PFX);

---- The ctestodbcset class generated in the above example is derived from CRecordset, in order to use the RFX mechanism, it declares two member variables: cstring m_name and cstring m_age, respectively correspond to [Name] in the database table file, respectively. [AGE] field. In the CTestodbcSet class, you can see the two RFX functions in the DofieldExchange (CfieldExchange * PFX):

---- RFX_Text (PFX, _T ("[Name]"), M_Name);

---- RFX_Text (PFX, _T ("[AGE]"), M_AGE);

---- PFX parameter is the CfieldExchange class pair of DofieldExchange passed.

DDX Simple ---- DDX is the abbreviation of Dialog Data Exchange, meaning that the dialog box is exchanged. It built a two-way parallel system between the visual controls of the dialog box and the member variable (Member Variables) that enables users to view and modify variables in the controls on the control.

---- Similar record field data exchange, the core of dialog data exchange is the virtual function DODATAEXCHANGE in the CRecordView class, and the DDX function is called in DODATAEXChange, which provides a pointer to the CDXChange class object to the DDX function. The prototype is : ---- Virtual Void DodataExchange (CDATAEXCHAN? PDX);

---- Enter the function ctestodbc :: DODATAEXCHANGE

---- Take the interpretation of the interpretation of the sequence, edit the auto-generated dialog box IDD_testodbc_form, this dialog box only one static text object "Todo: Place Form Controls On this Dialog.". It is a self-active numeral text, which shows the controls on this dialog box. Delete this article, add two edit box objects (Edit Box) IDC_EDit1 and IDC_EDit2, press the mouse right button on idc_edit1, select the [CLASWIZARD] into the Class Attribute Edit Dialog box in the pop-up menu. Select [MEMBER VARIABLES] attribute, select IDC_EDIT1 in [Control IDs], then press the [Add Variable] button to select the variable corresponding to it, select m_pset - $ # @ 62; m_name in the drop-down list box [MEMBER VARIABLE] , Press [OK] to return. Use the same method to select m_pset - $ # @ 62; m_age.

---- Reverse the dialog box editing, then enter the class ctestodbcView source file, add two DDX call functions in the function DODATAEXChange:

---- DDX_FIELDTEXT (PDX, IDC_EDit1, m_pset - $ # @ 62; m_name, m_pset);

---- DDX_FIELDTEXT (PDX, IDC_EDit2, m_pset - $ # @ 62; m_age, m_pset);

---- DDX_FIELDTEXT function builds a set of establishments between the editing controls of the dialog box and recorded fields. It can automatically manage the following types of data: int, short, long, dword, cstring, float, double, bool, and byte. Its four parameters are:

A pointer pointing to the object of the CDataExchange class;

The ID number of the dialog box control with the data exchange;

A field in the record;

Recording set with data exchange. ---- In DDX bidirectional data exchange, the user does not directly call the DofieldExchange function, but call the function updatedata (Bool Direct). This function of this function determines the direction of the data exchange: ---- Direct = false with record Field value update control value

---- Direct = TRUE updates the field value for the record value

---- Example I added an [SAVE] button in the dialog box, save the value of the control in its event:

Void ctestodbcview :: onbuttonsave () {.. .. ..updatedata (true);....} DDX and RFX relationships and comparison --- From above, RFX is data exchange in database programming The internal basis, which is more closely coupled to the recordset object (CRecordset), which is hidden in the background; DDX is the basis for the data exchange in the database programming in the dialog interface, which is more closely related to the view object (CRecordView) The same is displayed in the front desk. At the end, we use a picture to show their relationships:

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

New Post(0)