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

1

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

Eliath answered 11/7, 2012 at 12:32 Comment(0)
H
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().
Hiss answered 11/7, 2012 at 13:19 Comment(4)
Better yet, just declare errorProvider1 with stack semantics so no delete call is necessary at all.Dialogism
@Frédéric Hamidi Thanks for your reply now it is working fine.Eliath
@Dialogism Thanks for reply... How can I use errorProvider1 with stack semantics. Can you explain or give any example.Eliath
@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.Dialogism

© 2022 - 2024 — McMap. All rights reserved.