Hello,
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?
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…
class TOperInfo
enum TOperType
OperNull
OperMult
OperDiv
OperPlus
OperSous
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?
BR
BB
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 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.
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.
BB