MapWindow 4 - Plugins : MapWindow Discussion Forum
Attachments: Code.docx (16.2 KB) mapwin form.jpg (117.2 KB) mapwin form(expected).jpg (129.2 KB)
Hello, Can anyone tell me what is the meaning of the error, "Reference to a non-shared member requires an object reference". Actually, ..... I have my own plugin whcih opens a form inside mapwindowgis 4.8.7.
plugin code problem
Posted by:
raajiswetha111 ()
Date: March 30, 2012 10:55PM
Hello,
Can anyone tell me what is the meaning of the error,
"Reference to a non-shared member requires an object reference".
Actually,
..... I have my own plugin whcih opens a form inside mapwindowgis 4.8.7.
..... I designed a button inside the form which should open one more form.
.....the above error comes only when i give code for the second form to open.
I tried doing the same exercise within vb studio 2008 and there is no such error and the forms open correctly.
I am attaching the code and its related error shown.
1. Plugin code is in ........ code.doc
2. Form opened in mapwindow gis 4.8.7 is in ........ mapwin form.jpg
In this the click of "more details on domestic pollution" button should open another form but it is not opening.
3. Form opened in vb with no error is in ........ mapwin form(expected).jpg
Someone pls tell me what this error means and what should i do to rectify this.Pls.
Regards
Raaji
Can anyone tell me what is the meaning of the error,
"Reference to a non-shared member requires an object reference".
Actually,
..... I have my own plugin whcih opens a form inside mapwindowgis 4.8.7.
..... I designed a button inside the form which should open one more form.
.....the above error comes only when i give code for the second form to open.
I tried doing the same exercise within vb studio 2008 and there is no such error and the forms open correctly.
I am attaching the code and its related error shown.
1. Plugin code is in ........ code.doc
2. Form opened in mapwindow gis 4.8.7 is in ........ mapwin form.jpg
In this the click of "more details on domestic pollution" button should open another form but it is not opening.
3. Form opened in vb with no error is in ........ mapwin form(expected).jpg
Someone pls tell me what this error means and what should i do to rectify this.Pls.
Regards
Raaji
Attachments: Code.docx (16.2 KB) mapwin form.jpg (117.2 KB) mapwin form(expected).jpg (129.2 KB)
Re: plugin code problem
Posted by:
Chris George ()
Date: April 01, 2012 12:31PM
There is an explanation here [msdn.microsoft.com] It is probably not very clear to the non-programmer, but the final example shows one way to fix the problem.
To explain it more simply, suppose the error arises where you are calling a method called "f", in a class called "C", so you have written f(...) or perhaps C.f(...). If C has what are called "instance" variables, ie variables declared at the top level, not inside a method like "f", then you might have different instances of C, ie different objects made from C, and these objects might have different values of their variables. So the compiler rightly complains that it doesn't know which object's f it is to call. To make this more concrete, suppose C is a class representing a house, and f is count_rooms. If you are asked to say how many rooms a house has, you might well say "which house?", and this is what the error means. Now suppose there is another method in the house class, room_area, and the room (containing all relevant dimensions) is passed as a parameter, and you have put room_area in the house class. [Not a very good example, but bear with me.] Now the result depends on the parameter only, not on the particular house, and you can safely make this method "shared", ie it is the same method for all houses.
There are two possible solutions. One is to try changing "Public" to "Shared" in the definition of f. If this works, your error will go away. It means that either C does not have any instance variables, or that f does not depend on them. (Microsoft advice is not to do this, but I think it is a good idea to make it clear what functions are shared.)
If you get an error in the f definition, replace "Shared" with "Public" again in the definition of f and use the example on the Microsoft page mentioned above. Ie you would write instead of f(...) or C.f(...) something like
Dim CInstance as New C
CInstance.f(...)
To explain it more simply, suppose the error arises where you are calling a method called "f", in a class called "C", so you have written f(...) or perhaps C.f(...). If C has what are called "instance" variables, ie variables declared at the top level, not inside a method like "f", then you might have different instances of C, ie different objects made from C, and these objects might have different values of their variables. So the compiler rightly complains that it doesn't know which object's f it is to call. To make this more concrete, suppose C is a class representing a house, and f is count_rooms. If you are asked to say how many rooms a house has, you might well say "which house?", and this is what the error means. Now suppose there is another method in the house class, room_area, and the room (containing all relevant dimensions) is passed as a parameter, and you have put room_area in the house class. [Not a very good example, but bear with me.] Now the result depends on the parameter only, not on the particular house, and you can safely make this method "shared", ie it is the same method for all houses.
There are two possible solutions. One is to try changing "Public" to "Shared" in the definition of f. If this works, your error will go away. It means that either C does not have any instance variables, or that f does not depend on them. (Microsoft advice is not to do this, but I think it is a good idea to make it clear what functions are shared.)
If you get an error in the f definition, replace "Shared" with "Public" again in the definition of f and use the example on the Microsoft page mentioned above. Ie you would write instead of f(...) or C.f(...) something like
Dim CInstance as New C
CInstance.f(...)
Re: answer to myself
Posted by:
raajiswetha111 ()
Date: April 02, 2012 12:19AM
Hello all,
If any of you come across the problem,
"Reference to a non-shared member requires an object reference".
it means that your parent form and the other form need some connection to be referred. So there is actually two ways to resolve this error,
1. Declare the child form or textbox or whatever as new form or textbox or whatever once again and them continue the task it has to do.
For example if you want your child form to be opened inside your parent form and if you come across the above error then,
Remodify your code to this before loading your child form,
Dim form2 as new form
Form2.(task)
This redeclaration solve the above error
OR
2. Open your child form by referring your parent form like this,
Ie. form1.form2.(task)
Regards
Raaji
If any of you come across the problem,
"Reference to a non-shared member requires an object reference".
it means that your parent form and the other form need some connection to be referred. So there is actually two ways to resolve this error,
1. Declare the child form or textbox or whatever as new form or textbox or whatever once again and them continue the task it has to do.
For example if you want your child form to be opened inside your parent form and if you come across the above error then,
Remodify your code to this before loading your child form,
Dim form2 as new form
Form2.(task)
This redeclaration solve the above error
OR
2. Open your child form by referring your parent form like this,
Ie. form1.form2.(task)
Regards
Raaji
Sorry, only registered users may post in this forum.


