Dodataexchange (cdataexchange * PDX)

Source: Internet
Author: User
Tags ole

 

Dodataexchange (cdataexchange * PDX) is an important function of MFC cwnd.

In this function, you can use a series of ddx_xxxx (...) functions to implement data interaction between the UI and data, and use ddv_xxx (...) for data verification. For example:

// Simple text operations

Void

Afxapi
Ddx_text (cdataexchange *
PDX, int NIDC,
Byte & value); // special control types

Void

Afxapi
Ddx_check (cdataexchange *
PDX, int NIDC,
Int & value );

// Number of characters

Void

Afxapi
Ddv_maxchars (cdataexchange *
PDX, cstring
Const & value,
Int nchars );

....

These DDV may not meet our needs. However, you can use the cdataexchange parameter PDX to verify your data in dodataexchange. Use PDX-> m_bsaveandvalidate to determine whether updatedata (true) or updatedata (false ). If the verification fails, PDX-> fail () is triggered.

// Cdataexchange-for data exchange and validation

Class

Cdataexchange

{

// Attributes

Public

 

: Bool
M_bsaveandvalidate;
// True => Save and validate data

 

// Operations (for implementors of DDX and DDV procs)

Cwnd *
M_pdlgwnd;
// Container usually a dialog

 

 

 

Hwnd
Preparectrl (int
NIDC );
Hwnd
Prepareeditctrl (int
NIDC );
Void
Fail ();
// Will throw exception

 

Cdataexchange (cwnd *
Pdlgwnd,
Bool
Bsaveandvalidate );

 

Colecontrolsite *
Prepareolectrl (int
NIDC );
// For OLE controls in Dialog

// Implementation

 

Uint
M_idlastcontrol;
// Last control used (for validation)

 

Bool
M_beditlastcontrol;
// Last control was an edit item

};

It is worth noting that the preparexxx function. When data verification fails, the focus can be restored to the failed control. The custom data verification function can have the following structure:

Template <class T>

Void ddv_myvalidate (cdataexchange *
PDX, uint nctrlid, T & Data ...)

{

PDX-> preparectrl (nctrlid );

If (PDX-> m_bsaveandvalidate)

{

Bool bvalid = .....;

If (! Bvalid)

PDX-> fail ();

Else

Data =...; // get data from UI

}

Else

{

// Set data to contorl

}

}

 

Dodataexchange (cdataexchange * PDX) is an important function of MFC cwnd.

In this function, you can use a series of ddx_xxxx (...) functions to implement data interaction between the UI and data, and use ddv_xxx (...) for data verification. For example:

// Simple text operations

Void

Afxapi
Ddx_text (cdataexchange *
PDX, int NIDC,
Byte & value); // special control types

Void

Afxapi
Ddx_check (cdataexchange *
PDX, int NIDC,
Int & value );

// Number of characters

Void

Afxapi
Ddv_maxchars (cdataexchange *
PDX, cstring
Const & value,
Int nchars );

....

These DDV may not meet our needs. However, you can use the cdataexchange parameter PDX to verify your data in dodataexchange. Use PDX-> m_bsaveandvalidate to determine whether updatedata (true) or updatedata (false ). If the verification fails, PDX-> fail () is triggered.

// Cdataexchange-for data exchange and validation

Class

Cdataexchange

{

// Attributes

Public

 

: Bool
M_bsaveandvalidate;
// True => Save and validate data

 

// Operations (for implementors of DDX and DDV procs)

Cwnd *
M_pdlgwnd;
// Container usually a dialog

 

 

 

Hwnd
Preparectrl (int
NIDC );
Hwnd
Prepareeditctrl (int
NIDC );
Void
Fail ();
// Will throw exception

 

Cdataexchange (cwnd *
Pdlgwnd,
Bool
Bsaveandvalidate );

 

Colecontrolsite *
Prepareolectrl (int
NIDC );
// For OLE controls in Dialog

// Implementation

 

Uint
M_idlastcontrol;
// Last control used (for validation)

 

Bool
M_beditlastcontrol;
// Last control was an edit item

};

It is worth noting that the preparexxx function. When data verification fails, the focus can be restored to the failed control. The custom data verification function can have the following structure:

Template <class T>

Void ddv_myvalidate (cdataexchange *
PDX, uint nctrlid, T & Data ...)

{

PDX-> preparectrl (nctrlid );

If (PDX-> m_bsaveandvalidate)

{

Bool bvalid = .....;

If (! Bvalid)

PDX-> fail ();

Else

Data =...; // get data from UI

}

Else

{

// Set data to contorl

}

}

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.