Howdy,
I am still a newbie with POL and Palm development so please bear with me.
I populated my Database with ListRectType as the record type.
typedef struct
{
CString LastName;
CString FirstName;
}ListRectType;
The main goal for this demo app is:
1. To display the record's data.
2. To have the ability to update the record's data.
This is the function I use to display the record's data:
CTestListCtrl derives from CDBListCtrl
/// Return item's text.
const Char* CTestListCtrl::GetItemText
(Int16 nItemNum, UInt16 wIndex)
{
m_strText = "";
MemHandle recordHandle(m_pDatabase->QueryRecord(wIndex));
ListRectType* tempObj =
(ListRectType*)MemHandleLock(recordHandle);
m_strText += tempObj->LastName + ", " + tempObj->FirstName;
MemHandleUnlock(recordHandle);
return m_strText;
}
And this is what I have to modify the record's data:
// Modify button handler
Boolean CStudentListForm::OnModify
(EventPtr pEvent, Boolean& bHandled)
{
Int16 nSelection = m_lstTest.GetSelection();
if (nSelection != -1)
{
UInt16 wIndex = m_lstTest.GetCurrentIndex();
CStarterApp* pApp;
pApp = (CStarterApp*)CStarterApp::GetInstance();
CDatabase* pDatabase = pApp->GetDatabase();
CRecord temp;
pDatabase->GetRecord(temp, wIndex);
ListRectType* tempObj = (ListRectType*)(temp.Lock());
//This is for DDX
CEditRecordDialog dlgEditRecord;
dlgEditRecord.m_FirstNameTxt = tempObj->FirstName;
dlgEditRecord.m_LastNameTxt = tempObj->LastName;
if (dlgEditRecord.DoDialog(EditFormForm) == EditFormOKButton)
{
UInt32 onLocationOffset = OffsetOf(ListRectType, LastName);
temp.Write(onLocationOffset, new CString
(dlgEditRecord.m_LastNameTxt),sizeof(dlgEditRecord.m_LastNameTxt));
temp.ReleaseRecord();
m_lstTest.DrawList();
}
}
return true;
}
Everything works perfectly fine but I am pretty sure that I did something wrong
in this line:
temp.Write(onLocationOffset, new
CString(dlgEditRecord.m_LastNameTxt),sizeof(dlgEditRecord.m_LastNameTxt));
I called 'new' every time I do a CRecord::Write which I believe is wrong
because that means I kept on allocating memory. I am basically filling up the
heap.
But if I don't do that and do this:
temp.Write(onLocationOffset,
&(dlgEditRecord.m_LastNameTxt),sizeof(dlgEditRecord.m_LastNameTxt));
I will get this error msg whenever I try to update a different record:
"POL Starter(1.0) just read from memory location 0x00037BD6, which is in an
unallocated chunk of memory."
This error msg won't popped up if I keep on updating the same record.
The error msg seems to be pointing out that I do need to allocate the CString
but this will cause a mem-leak since no one is deleting it.
Please enlighten me.
--
For information on using the ACCESS Developer Forums, or to unsubscribe, please
see http://www.access-company.com/developers/forums/