Pagepanel object

I have to define rather a lot of pages in the Pagepanel object. With many pages it is easy to get confused about the purpose of each page.
Is it possible to name each page? Couldn’t find it.

No, the pages cannot be named.

But to help you keep your code clearer, you could certainly create constants that you use to set PagePanel.Value.

Ah yes, good thinking :)!

Thanks.

I personally use enumerations for this. That way, if I meant to reorder or add a page in the middle, it’s easily done. I rely on the auto-numbering of 0-n.

I do not see so many differences between structure and enumerations…

They’re completely different animals.

Structures are a “compound data type”, which means you can combine multiple data types (i.e. numeric values, strings, etc.) into a single type. The difference between an object and a structure is two fold: (1) An object can reference other objects, while structures can’t have objects as properties. (2) Structures are data types in that they point directly to the value in memory, while an object is first a collection of pointers. An example would be:

[code]Structure Name
FirstName As String * 30 // The * 30 gives the permissible length of the string
LastName As String *30
End Structure

Dim NewName As Name
Name.FirstName = “Jason”
Name.LastName = “Adams”[/code]

Enumerations, on the other hand, are a numbered collection of “constants”. Really, enumerations don’t have to be numbers, but in Xojo that’s what you’re limited to (there’s a feature request to extend this). An example would be:

[code]Enumeration Fruit
Apple
Orange
Banana
Mango = 20
End Enumeration

Dim MyFruit As Fruit
Dim Value As Integer

MyFruit = Fruit.Banana
Value = Int32(MyFruit) // Value is now 2[/code]

Note that the values will automatically set from the top-down starting from 0, unless specified — Fruit.Mango is therefore 20.

Hope this helps! :slight_smile:

Hello Jason,

thanks for the quick reply. I use Structures at the moment and it’s very useful and versatile. I have not come across a problem that I would have to solve with enumerations, but your explanation made me think about it.

Enumerations don’t solve problems, per se; think of them like a compound constant.

too bad…:frowning:

Erm… That’s not exactly the response I would’ve anticipated.

What I meant by what I said is that a program could be written without ever using enumerations, and it’d work just fine. In other words, they’re not irreplaceable. But, like using constants, they’re good tools to use for writing organized, and easily manageable code.

I know… it is just that I had not used them before, in Xojo, that is. I used Delphi for 12 years and enumerations are part of Pascal, or Object Pascal.

Well, If I define on the App level a Structure, and I want to use it in a Window, I can’t define it.
I declared a ‘CDDObject’ structure with a couple of declarations like ’ Name as String * 32". No problem.

if my mainWindow, I click a button and in the Action event I want the following:

dim newCDD as new CDDObject newCDD.Name =...

Compiler returns an error stating that ‘There is no class with this name’. How come?
Using

dim newCDD as new App.CDDObject invokes the same error.

The “New” operator works [i]only[/] with objects, as it refers to object construction. Structures are a data type, not an object, so just do this:

dim newCDD as CDDObject NewCDD.Name = ...

OK, but what is its scope?

Scope of the variable or the structure? Either way that depends on where you put it, normal scoping applies.

Mmm… I want the Structure to be available in all Methods and Events of a Window. I tried to create it as a property of the Window but it doesn’t work. I can create the Structure but it is not recognized in any Method or Event…

When you define it on the App class it’s not global is why.
Define it in a module as “global” and this will work just fine.
Secondly structures are not “objects” - you don’t “new” them.
Treat them more like integers, doubles etc - VERY basic data types.