6

I am trying to use ErrorProvider Class to show error on checkbox. I am able to show the error using the following code

errorProvider1->SetError(checkBox1,"Error");

But when I am trying to dispose this errorProvider using the following code

errorProvider1->Dispose();

Then this line is showing error

error C2039: 'Dispose' : is not a member of 'System::Windows::Forms::ErrorProvider'

This Code I am able to run successfully in vc# but not in vc++;

But since My requirement is to use this in vc++.

Can anybody please tell me what is the problem in this code.

Thanks in Advance

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Mayank Prabhakar
  • 133
  • 2
  • 6
  • 14

1 Answers1

8

According to this article, the IDisposable pattern is different in C++/CLI, and you cannot implement or call Dispose() methods in that language.

You have to use the delete operator instead:

errorProvider1->SetError(checkBox1,"Error");
delete errorProvider1;  // Equivalent to errorProvider1->Dispose().
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • 2
    Better yet, just declare `errorProvider1` with stack semantics so no `delete` call is necessary at all. – ildjarn Jul 11 '12 at 20:20
  • @Frédéric Hamidi Thanks for your reply now it is working fine. – Mayank Prabhakar Jul 12 '12 at 04:42
  • @ildjarn Thanks for reply... How can I use errorProvider1 with stack semantics. Can you explain or give any example. – Mayank Prabhakar Jul 12 '12 at 04:44
  • @MayankPrabhakar : You need to show where and how `errorProvider1` is declared. :-] E.g. if it's at class scope the answer will be different then if it were in block scope. – ildjarn Jul 12 '12 at 04:57