So, you want to report errors in a printf / sprintf way? Check this out…
- [cpp]
#include
//—–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);
}
[/cpp]
ps: don’t forget to declare void __cdecl TForm1::ShowError(const char *format, …) in your TForm class ![]()
Programmers should be trusted. If your brain surgeon told you the operation you need takes five hours, would you pressure him to do it in three? 