Defining array length with a constant

Hi,

This is my first posting for support after working with Xojo for 3 or 4 years without major problem. I hope someone can point out what I’m doing wrong here. Here’s a description of the problem.

I’m working on an application with a lot of fixed length arrays - all with the same length.

I want to define the array length as a constant so that if it needs to be increased in the future, it’ll just be a one line change.

So, I’ve defined a public constant on the App:-

#tag Constant, Name = MAXELEMENTS, Type = Double, Dynamic = False, Default = “49”, Scope = Public
#tag EndConstant

I can then do the following in code:-

Dim anArray(App.MAXELEMENTS) as Integer

No problems there.

I then try and define an object array property on a class (e.g. MyClass)

#tag Property, Flags = &h0
MyArrayProperty(App.MAXELEMENTS) As Integer
#tag EndProperty

This gives a compiler error in Xojo:-

MyClass.MyArrayProperty(App.MAXELEMENTS) Declaration - “Self” does not mean anything in a module method MyArrayProperty(App.MAXELEMENTS) As Integer

Interestingly (or maybe not) this compiles under RealStudio and works fine.

I hope someone can help,

Thanks in advance,

Peter

App is a FUNCTION CALL and therefore NOT A “constant”
Move your constant to a module and things should be fine

I can’t reproduce this at all. I defined a constant in App, kUpper = 6, then a property in my new Class, Arr(App.kUpper) As Integer, and it compiles just fine. I can even rename my App object without an issue.

I can in 2016r4.1
2017r1 does seem to do the right thing though

Biut I have no idea which version he’s using

Interesting. So what are we doing differently?

I’m doing it right
Not sure about you :stuck_out_tongue:

Honestly I have no idea

I simply can’t get it to stop working, but if you want to look to compare:

https://www.dropbox.com/s/18xk8c7tksnhlo8/App%20Constant.xojo_binary_project?dl=0

As I said this fails in 2016r4.1
Not in 2017r1
And your example does as well (see https://forum.xojo.com/conversation/post/323231) :stuck_out_tongue:

But I have no idea which version Peter is using
I suspect it must be 2016r4.1

2016r4.1 is so yesterday.

Its why I get paid the big bucks to hunt this sort of stuff down :slight_smile:

Thanks for all the replies.

I’m actually using 2015 2.1 - due to some plug-in incompatibilities - but I’ve tried compiling under 2016 4.1 and 2015 3, and they both come up with this same strange compiler error (“Self does not mean anything in a module method” doesn’t really seem relevant for this error).

I have an old version of RealStudio (2012 2.1) and it compiles under that OK and works fine.

I’ll try 2017 1 tomorrow morning (I’m on European time). If that fixes it, I guess this will be a good time to sort out those plug-ins.

Thanks again

its absolutely relevant

put your constant in a MODULE, make it GLOBAL, and this issue will be gone

Norman,

Thanks, that does work - I can’t really see why - but it seems unappreciative to dwell on the ‘whys’.

Thanks again for your help.

Peter