Understanding shared methods

Doing a bit of refactoring. I’ve got a class (“MailFields”) that holds some data. So far I’ve always passed the class around, made a copy and got the class back. Since I’m usually dealing with GBs of data I want to eliminate the copying of the data. But I can’t seem to understand shared methods.

The class is simple. The normal properties were converted to shared ones:

Shared ContentDescription As String Shared ContentDisposition As String Shared ContentDispositionCharset As string

and so on. Between parsing runs I need to reset the data with

[code]Sub Reset()

ContentDescription = “”
ContentDisposition = “”
ContentDispositionCharset = “”
'and so on

End Sub[/code]

But now Xojo barfs at

MailFields.Reset

with the error message “Static reference to instance method”. At the moment I want to keep this as class because I’m not sure how I want to extend this class. Most likely a module would work at the moment, too.

How do I need to use the shared method here?

Xojo 2015r22, Mac OS 10.10.2.

What you are trying to do is calling an instance method like a class method (=shared method). Reset is an instance method, so it must be called on an instance of MailFields:

aMailFieldsInstance.Reset()

Make Reset a Shared method. ?

Reset already is a shared method. That’s what makes this so confusing.

The error message is telling you what I described: Static reference to instance method. You are accessing an instance method in a shared method without having prepended the method with the instance in your code.

By the way, your code above doesn’t say Shared Sub Reset, it says Sub Reset which makes it an instance method.

So this isn’t true?

Beatrix, it seems the root problem is the understanding of Shared vs. Instance. Here is a blog post that I found. It is for VB.NET, but it really doesn’t matter, it could have been for any number of languages, the Shared vs. Instance is what is needed here.

http://blog.giffordconsulting.com/2006/08/object-oriented-overview-and-shared-vs.html

Once you understand the difference of Shared and Instance methods, your error will make sense and I’m sure you will come to an easy solution based on your needs.

@Will and Eli: I copied the method from the old version of my code. But the error message occurred for Reset being Static.

@Jeremy: thanks, that helped. “Shared” is a not very clear name and I will simply use a module for now.