FIX: Edit() After Requery() May Produce Incorrect ResultsLast reviewed: September 18, 1997Article ID: Q116409 |
1.50
WINDOWS
kbprg kbfixlist kbbuglist
The information in this article applies to:
SYMPTOMSIn an MFC database application using CRecordsets:
CAUSEThe reason for this behavior is that Requery() does not reset the m_nEditMode variable that gets set when you call Edit(), nor does it flush the CMemFile-based record cache. The second time Edit() is called, m_nEditMode indicates that the recordset is in Edit mode and therefore is reset, with the cache restored to the record fields. This behavior of the second call to Edit() is expected according to the specification of the function [see the Edit() function description in the "MFC Library Reference"].
RESOLUTIONTo work around this, override CRecordset::Requery() in your derived CRecordset class and call the ReleaseCopyBuffer() function. This resets the Edit-mode member variable, m_nEditMode, and also flushes the record cache. The sample code in the "MORE INFORMATION" section, below, includes an example of an overridden Requery().
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in MFC version 2.51, included with Visual C++ version 1.51.
MORE INFORMATIONThe CRecordset class contains two member variables called "m_pmemfile" and "m_par". m_pmemfile is a pointer to a CMemFile object used to hold the current record; m_par is a pointer to an archive used to hold the CMemFile. m_pmemfile is the cache that remains persistent between calls to "Edit()" if no reopen or requery is done. "ReleaseCopyBuffer()" frees the objects associated with these pointers and thus flushes any values that might be restored on a second edit call. Edit() then reallocates the CMemFile object and archive and reloads the cache buffer.
Sample Code
// CMyRecordset is derived from CRecordset. BOOL CMyRecordset::Requery() { BOOL bRC = CRecordset::Requery(); ReleaseCopyBuffer(); return bRC; } REFERENCESFor other articles pertaining to problems with CRecordset::Requery(), query on "Requery" and "CRecordset".
|
Additional reference words: InitRecord 1.50 2.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |