Ik ben een programma aan het schrijven voor Windows CE 3.0 met Visual Tools 3.0 (eVC++) en gebruik daarbij MFC. Nou werkt alles fijn, maar het opslaan van files gaat niet goed. Ik heb de volgende code:
Het probleem is dat er, bij het laden, 4x het laatste item (Question) staat in plaats van 4 verschillende Questions. De MessageBox in deze procedure output netjes de dingen die moeten worden geoutput. Het ligt niet aan m'n OnLoad-methode, want als ik het bestand met notepad open, staat er inderdaad maar 1 Question object.
Ben er al een paar uur mee bezig, erger me ook aan de traagheid van MSDN search ("Recently, we've improved the search, so that you can concentrate on writing great code" *ahum*
)
Wie weet raad?
Voor de volledigheid ook maar even de class Question erbij:
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| void CCetestDlg::OnSave() { // TODO: Add your command handler code here CFileDialog fd(FALSE,_T("cet"),NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL,(CWnd*)this); if(fd.DoModal()==IDOK) { CFile file(fd.GetPathName(),CFile::modeCreate|CFile::modeReadWrite|CFile::typeBinary); CArchive archive(&file,CArchive::store); POSITION pos = _questions.GetHeadPosition(); for (int i=0;i < _questions.GetCount();i++) { Question px = _questions.GetNext(pos); archive << (CObject*)&px; CString x; x.Format(_T("Question %s %s %d"),px.answer, px.question, px.status); MessageBox(x,x,MB_OK); } archive.Flush(); archive.Close(); file.Close(); } m_filename = fd.GetPathName(); SetDlgItemText(IDC_FILENAME,m_filename); } |
Het probleem is dat er, bij het laden, 4x het laatste item (Question) staat in plaats van 4 verschillende Questions. De MessageBox in deze procedure output netjes de dingen die moeten worden geoutput. Het ligt niet aan m'n OnLoad-methode, want als ik het bestand met notepad open, staat er inderdaad maar 1 Question object.
Ben er al een paar uur mee bezig, erger me ook aan de traagheid van MSDN search ("Recently, we've improved the search, so that you can concentrate on writing great code" *ahum*
Wie weet raad?
Voor de volledigheid ook maar even de class Question erbij:
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
| // Question.h: interface for the Question class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_QUESTION_H__2BD8245A_5F28_4282_98CD_7598E3741639__INCLUDED_) #define AFX_QUESTION_H__2BD8245A_5F28_4282_98CD_7598E3741639__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class Question: public CObject { public: Question() { } virtual ~Question() { } Question operator =(Question& q) { question = q.question; answer = q.answer; status = q.status; } Question(Question& q) { question = q.question; answer = q.answer; status = q.status; } CString question; CString answer; int status; void Serialize(CArchive& ar) { if(ar.IsStoring()) { ar << question; ar << answer; ar << status; } else { ar >> question; ar >> answer; ar >> status; } } DECLARE_SERIAL(Question); }; #endif // !defined(AFX_QUESTION_H__2BD8245A_5F28_4282_98CD_7598E3741639__INCLUDED_) |
[ Voor 29% gewijzigd door MisterData op 15-07-2003 18:13 ]