R
Hallo zusammen,
ich hab ein kleines Programm, das bei jeden Error eine MessageBox aufmacht mit der dazugehörigen Fehlermeldung. Bist gestern lief´s prima, heute hab ich folgendes Prob:
Ich habe eine Methode fileDialog(), die via Do while und einem bool nur XML-Files zulässt und sollte man z.B. händisch eine txt einlesen wollen, wird eine Hinweisbox ausgegeben, dass nur XMLs geladen werden dürfen und der fileDialog() nochmal erneuert (do-while).
Ausserdem danach eine Methode parse(), die mit einem ErrorHandler versehen ist und einen Fehler beim Parsen ausspuckt.
Es ist irgendwie schei*** schwer zu erklären was das Prob ist:
Wenn jetzt beim Parsen ein Fehler entsteht, kommen Teile von anderen MessageBox-Nachrichten in der MessageBox des aktuellen Fehlers vor. WARUM?? Ich checks nicht. Muss man bei der Definition von MessageBoxen etwas beachten?
Anbei der Code:
//FileDialog():
CString fileDialog ()
{
CString file;
const char* outFile;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
MessageBox(NULL,
"MFC could not be initialized!\nThe programme will finish.",
"Secant_2_CSV - MFC Init failed",
MB_ICONERROR | MB_OK);
exit(1);
}
else
{
//TRUE: Open File Dialog, FALSE Save File Dialog
//NULL: Standard
//OFN_HIDEREADONLY: Standard
//only xml-files are shown
CFileDialog inDlg(TRUE,"xml",NULL,OFN_HIDEREADONLY,"XML-Files (.xml)|.xml|");
inDlg.m_ofn.lpstrTitle = "XML - File laden"; //sets the titel of the dialog
bool help = false;
//loops until either an xml-file is loaded or the "cancel" button is pressed
while (help==false)
{
if( inDlg.DoModal ()==IDOK) //by clicking "open"
{
if (inDlg.GetFileExt()!="xml")
{
MessageBox(inDlg,
"Wrong file extension! Only .xml",
"Secant_2_CSV - Wrong file extension",
MB_ICONASTERISK | MB_OK);
help=false;
}
else
{
file = inDlg.GetPathName();//path with filename
file.Replace("\","/"); //changes path from windows in unix - style like: C:\folder1\file1 to C:/folder1/file1
outFile = (LPCTSTR)file;//makes a CString to char
help=true;
}
}
else //if there´s clicked "cancel" the programme will finish
exit(1);
}
}
//if (outFile) parseFile(outFile);
return file;
}
//Parse:
ist ein einfach Aufruf in einer Methode, aber eigentlich für das Prob unwichtig:
parser->setErrorHandler(ha)
parser->parse(XMLFile)
//Error Handler:
#include <xercesc/sax/ErrorHandler.hpp>
#include <xercesc/util/XMLString.hpp>
#include <iostream>
#include <string.h>
using namespace std;
XERCES_CPP_NAMESPACE_USE
class MyErrorHandler : public ErrorHandler
{
public:
MyErrorHandler()
{
}
~MyErrorHandler()
{}
virtual void warning (const SAXParseException &exc)
{
CString msg1 = "Line: " + exc.getLineNumber();
CString msg2 = "\nColumn: " + exc.getColumnNumber();
CString msg3 = "\n";
CString msg4 = XMLString::transcode(exc.getMessage());
CString msg = msg1 + msg2 + msg3 + msg4;
MessageBox(NULL,
msg,
"Secant_2_CSV - Parsing Exception",
MB_ICONERROR | MB_OK);
exit(1);
}
virtual void error (const SAXParseException &exc)
{
CString msg1 = "Line: " + exc.getLineNumber();
CString msg2 = "\nColumn: " + exc.getColumnNumber();
CString msg3 = "\n";
CString msg4 = XMLString::transcode(exc.getMessage());
CString msg = msg1 + msg2 + msg3 + msg4;
MessageBox(NULL,
msg,
"Secant_2_CSV - Parsing Exception",
MB_ICONERROR | MB_OK);
exit(1);
}
virtual void fatalError (const SAXParseException &exc)
{
CString msg1 = "Line: " + exc.getLineNumber();
CString msg2 = "\nColumn: " + exc.getColumnNumber();
CString msg3 = "\n";
CString msg4 = XMLString::transcode(exc.getMessage());
CString msg = msg1 + msg2 + msg3 + msg4;
MessageBox(NULL,
msg,
"Secant_2_CSV - Parsing Exception",
MB_ICONERROR | MB_OK);
exit(1);
}
virtual void resetErrors ()
{
}
};