DDX and RFX should be used in ODBC

zhaozj2021-02-11  192

In ODBC, the ODBC class library in DDX and RFX MFC --- MFC Pin is available for the 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. ---- The following uses AppWizard in the VC to generate a simple sample program for use: ---- 1. Select [New] in [File], select file type in the pop-up dialog box [MFC AppWizard (EXE)]. 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 selecting the data library source file, the connection point is pressed, 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 is simple ---- RFX is the abnum 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. Some functions are: function data type RFX_BOOL BOOL

RFX_BYTE BYTE

RFX_BINARY CBYTEARRAY

RFX_DOUBLE DOUBLE

RFX_SINGLE FLOAT

RFX_INT INT

RFX_LONG LONIG

RFX_LONGBINARY Clongbinary

RFX_Text CString

RFX_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; the variable name that corresponds to the 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 exchange is the virtual function DOFIELDEXCHANGE in the CRecordset class, and the RFX function is called in DofieldExchange, which provides a pointer to the CfxChange class object to the RFX function, whose prototype is: ---- Virtual Void DofieldExchange (CfieldExChang  PFX); --- The ctestodbcset class generated in the above example is derived from CRecordset, in order to take advantage of the RFX mechanism, it declares two member variables: cstring m_name and cstring m_age, respectively correspond to the database [Name] and [AGE] fields in the table file. In the CTestodbcSet class overload method DofieldExchange (CfieldExChange * PFX), you can see two RFX functions: ---- RFX_Text (PFX, _T ("[name]"), m_name); ---- RFX_Text (PFX, _T ("[age]"), m_age); ---- PFX parameter is the CfieldExchange class object pointer passed for DofieldExchange. 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 function ctestodb :: DODATAEXCHANGE, this time there is no code in the function body, because we don't create a control in the dialog, no DDX mechanism . ---- 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 [Add Variable] button to select the variable corresponding to it, select m_pset -> m_name in the drop-down list box [MEMBER VARIABLE NAME], press [OK ] Returns. Use the same way to select m_pset -> m_age. ---- Exit dialog editing, then enter the class ctestodbcView source file, find two DDX call functions in the DODATAEXChange: ---- DDX_FieldText (PDX, IDC_EDIT1, M_PSET -> M_NAME, M_PSET); --- - DDX_FIELDTEXT (PDX, IDC_EDIT2, M_PSET -> M_PSET); ---- DDX_FIELDTEXT functions establish a connection between the editing control of the dialog and the field of records. 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 to the CDataExchange class object; the ID number of the dialog box control with the data exchange; one field in the record; the recordset of the recordset with the 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 Update the value of the recorded field value ---- For example, we add an [SAVE] button in the dialog box, save the value of the control in its event handler: Void ctestodbcview :: onbuttonsave ()

{

.. ....

Updatedata (TRUE);

.. ....

} DDX and RFX relationships and comparison - From the above, RFX is the internal basis of data exchange in database programming, which is more closely related to record set objects (CRecordset), which is hidden in the background; DDX It is the basis for the data exchange in the database programming in the dialog interface. It is more closely related to the view object (CRecordView), which is displayed in the front desk. At the end, we use a picture to show their relationships:

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

New Post(0)