Reporting formatted errors
So, you want to report errors in a printf / sprintf way? Check this out...
-
#include <stdarg.h>
-
//-----blah blah
-
-
void __fastcall TForm1::Button1Click(TObject *Sender)
-
{
-
AnsiString filename="c:\\mytestfile.txt";
-
-
if (!FileExists(filename))
-
ShowError("Cannot open file %s",filename.c_str());
-
}
-
-
-
void __cdecl TForm1::ShowError(const char *format, ...)
-
{
-
va_list args;
-
-
va_start(args,format);
-
-
AnsiString Buf="";
-
Buf.vprintf(format,args);
-
va_end(args);
-
-
Application->MessageBoxA(Buf.c_str(),"ERROR",MB_OK | MB_ICONERROR);
-
}
C++:
ps: don't forget to declare void __cdecl TForm1::ShowError(const char *format, ...) in your TForm class![]()
related things:
Author: Raz | On June 14th, 2007 | C++ Builder, [ En ] | No Comments
Q: So what can I do next?
A: You can Buy me a Beer or Coffee. You can say Hi! or peek on the related stuff. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Spammers: Beware of » my Dog! «




