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.
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:
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.
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.
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.