You are here: Home » Builder » [ En ] » Reporting formatted errors

Reporting formatted errors

14 June |

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 ;)

You like this post? Be the first of my friends to give me a beer! click here. Thanks!
Filed under

Builder, [ En ]

| Tags:

Comments are closed.