Declaration of constants

I am trying to translate from my previous language (Delphi) two declarations of constants, arrays in the most faithful, logical and shortest way of the original or does I use a dictionary, or integer indexes?

1: [code]type (class)
TOperType = (OperNull, OperMult, OperDiv, OperPlus, OperSous)

TOperInfo = Record // Here it’s OK
Priority: Byte;
NbOper: Integer;
2: Const OperInfos: array[TOperType] of TOperInfo = ( (Priority:0; NbOper:0;) // OperNull ,(Priority:2; NbOper:2;) // OperMult ,(Priority:2; NbOper:2;) // OperDiv ,(Priority:1; NbOper:2;) // OperPlus ,(Priority:1; NbOper:2;) // OperSous

Thanks in advance.


you cannot declare a constant as an array type in Xojo

not sure what you have converted TypeOperInfo and TOperType into so I cant offer replacement code

TOperType is just an enumeration, which Xojo supports (although, sadly not directly enumerable via a for-loop).
OperInfos would best be implemented with a Dictionary (since arrays are only indexable by integers). However, this wouldn’t be a constant…

something like


class TOperInfo
  enum TOperType 
  end enum

  property Priority as Uint8
  property NbOper as Integer

  Sub Constructor( priority as Uint8, nbOper as TOperType)
    self.priority = priority
    self. NbOper = nbOper
  end sub
end class

dim OperInfos() as TOperInfo = Array( new TOperInfo(0, ToperInfo.TOperType.OperNull) , _
      new TOperInfo(0, ToperInfo.TOperType.OperMult) , _
      new TOperInfo(2, ToperInfo.TOperType.OperDiv) , _
      new TOperInfo(1, ToperInfo.TOperType.OperPlus) , _
      new TOperInfo(1, ToperInfo.TOperType.OperSous) )

Wow, thank you very much Paul and Norman, and in addition you give me the code for the same price. Thanks to you I can finalize my project.
A subsidiary question: is it possible to create a class with its methods and properties directly from a text such as the one you provided me? I only knew the way using the menus and then by adding each method and property?


But I added a feature request to make something like this possible

Norman, I guess I need to be redirected to a post but the link is broken :frowning:

You need to install from the Extras page.

You can download and install the xojo feedback app here to fix those links into feedback :slight_smile:

Excuse me for digging up this old subject but as I was blocked, I moved towards other things. And thank you for the link to Feedback.
Norman if you come in the area :slight_smile: in fact when I test the array OperInfos() in the method where we initialize it, the values are well present (ex. with msgbox) but outside the method the variable is empty (ubound -1) and that’s what I do not understand.

would need a sample of your code to see why this might be

If UBound(-1) is in fact myArray() = -1 (or myArray() = Nil),

declare the array variable in a module as public.

Else: I do not know.

That’s usually because you have a Dim OperInfos() as TOperInfo in your code. That creates a local variable with the same name as your global property. Since the local variable is closer in scope, it is used in your code, leaving the global array untouched.

Argh, I’m embarrassed but a moment of shame is quickly over it seems. Indeed it is the Dim which is the cause, in my mind it corresponded to a Redim.
Thank you, all of you, a thousand times.

We’ve all done it at least once.