VB.NET error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

While trying to code in VB.NET I get this error: Reference to a non-shared
member requires an object reference.
Any suggestions/ideas why this occurs?

VBUser
 
VB User
While trying to code in VB.NET I get this error: Reference to a non-shared
member requires an object reference.
Any suggestions/ideas why this occurs?

Mostly is it because an error in your code.

Cor
 
Please post the code so that we can help, but from the message, it
appears that you are referencing a non-shared function from within a
shared one

e.g.

public class foo

public Function Getbar() as string
return "bar"
end function

public shared function GetMessage() as string
return "foo" + Getbar()
'<--- This line will cause the error
end function

end class
 
With myTempImage
.Aoi.SetBox(-1, 50, 50, 150, 150)
Dim mcregionsT As New McRegions
mcregionsT = IQL.McApplication.CreateOperator("McRegions",
myTempImage)
mcregionsT.Threshold.Execute()
mcregionsT.CleanUpBordersAndNoise(.Aoi,
mcRegionBorders.mcrbAllBorders, 25)
.PointFeatures.CopyFrom(mcregionsT.mpRgnCentroidAsPoint.value)
mcregionsT = Nothing
.SaveAs("C:/temp/CentroidSoy.tif")

End With



I get the error at the line: IQL.McApplication.CreateOperator

VBUser
 
VB said:
With myTempImage
.Aoi.SetBox(-1, 50, 50, 150, 150)
Dim mcregionsT As New McRegions
mcregionsT = IQL.McApplication.CreateOperator("McRegions",
myTempImage)
mcregionsT.Threshold.Execute()
mcregionsT.CleanUpBordersAndNoise(.Aoi,
mcRegionBorders.mcrbAllBorders, 25)
.PointFeatures.CopyFrom(mcregionsT.mpRgnCentroidAsPoint.value)
mcregionsT = Nothing
.SaveAs("C:/temp/CentroidSoy.tif")

End With



I get the error at the line: IQL.McApplication.CreateOperator

VBUser
:

mcregionsT = IQL.McApplication.CreateOperator("McRegions", myTempImage)

Where do you define an instance of IQL? Since you are trying to do an
operation against a member of IQL (McApplication in this case) somewhere
you have to create an instance of IQL (most likely using new statement)
What you have would be fine if CreateOperator was marked as "shared"
which is is not, hence the error message.


Dim mcregionsT As New McRegions
This is an error. What you are doing is creating a new instance of
McRegions. Then the very next statement you lose that instance and
point to another new instance that is returned by IQL.McAppliction.....

Instead do:
Dim mcregionsT as McRegions
This makes a pointer that will point to an McRegions object but doesn't
just yet. Your next line then have mcregionsT point to the object.


Chris
 
Back
Top