An object reference is required for the nonstatic field, method, or property .... why??
-
hello, I'm trying to take a string from a dialog box and pass it to another form, here's my code password.cs
... private String tmpPassStore; ... private void pass_ok_Click(object sender, System.EventArgs e) { tmpPassStore=this.passText.Text; Form1.changePass(tmpPassStore); }
form1.cs... public String DBPassword ; ... public void changePass(String pwd) { this.DBPassword=pwd; }
but at compile time, I receive the following error: D:\Projects\myBusinnes\password.cs(120): An object reference is required for the nonstatic field, method, or property 'myBusinnes.Form1.changePass(string)' why??? I pass an object of type string... Thanks in advance Paolo -
hello, I'm trying to take a string from a dialog box and pass it to another form, here's my code password.cs
... private String tmpPassStore; ... private void pass_ok_Click(object sender, System.EventArgs e) { tmpPassStore=this.passText.Text; Form1.changePass(tmpPassStore); }
form1.cs... public String DBPassword ; ... public void changePass(String pwd) { this.DBPassword=pwd; }
but at compile time, I receive the following error: D:\Projects\myBusinnes\password.cs(120): An object reference is required for the nonstatic field, method, or property 'myBusinnes.Form1.changePass(string)' why??? I pass an object of type string... Thanks in advance PaoloThe compiler doesn't complain about the string. To call the nonstatic method "changePass" of your "Form1" class you need an object of this class.
-
The compiler doesn't complain about the string. To call the nonstatic method "changePass" of your "Form1" class you need an object of this class.
and excuse me how do I fix that?? Form1 calls password's form creating a new instance of the password object, how do I tell password's one to relay to form1 object?? thanks Paolo
-
and excuse me how do I fix that?? Form1 calls password's form creating a new instance of the password object, how do I tell password's one to relay to form1 object?? thanks Paolo
-
and excuse me how do I fix that?? Form1 calls password's form creating a new instance of the password object, how do I tell password's one to relay to form1 object?? thanks Paolo
It's not working because Form1 doesn't exist in the context of the Password form. "There is no reference to an object of type Form1." In other words, in Form1, it created an object of type Password (form). Form1 knows everything public about the Password object. The Password object, on the other hand, knows nothing of the object that created it (Form1). As a rule of thumb, Parent objects create child objects, know everything about them, and can manipulate them. Child objects know nothing of the parents that created them and, hence, can't directly modify them. 3rd option... Create a Public field on the Password form and have Form1 look at that field and retrieve the string itself. Instead of trying to pass the string from the Password form to Form1, have Form1 pickup the string from the Password form. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome