Rather than creating 3 properties, it creates the same property with a new name over and over again. Is there a way to ‘next’ so I can execute a new instance of the DoCommand ? I’m trying to automate the build of some ~300 properties, I REALLY don’t want to spend a week doing it by hand.
I’m not sure about a IDE script, but you might be able to do copy/paste right into the .xojo_code if you save in a non-binary format.
It would be the same amount of copying and pasting as if you had made an IDE script.
Curious though, why do you need 300 properties? Could you not use one dictionary property?
Rather than creating 3 properties, it creates the same property with a new name over and over again. Is there a way to ‘next’ so I can execute a new instance of the DoCommand ? I’m trying to automate the build of some ~300 properties, I REALLY don’t want to spend a week doing it by hand.
Thoughts?[/quote]
300 properties sounds to me like a poor design decision somewhere
A little background on my app, I’m doing text file reads and writes, using customized user data to influence what I write into the output file. The way I’m structuring my app is that I want to store about 300 globally defined variables (properties) that various methods in the app will access to interact with each other. Today I’m defining these in code within a single method, but I’m outgrowing that model, and want to globally scope these particular variables. Based on the way I’m reading and writing to the data, and the types of things I’m doing to it, my current skill level, or a combination of both, I’m actually pretty happy with this approach, and it seems to meet my needs well. All I’m really trying to accomplish is defining a large quantity of globally scoped variables that various classes can easily access. If creating these as a property isn’t the best / only way to accomplish this, I’m all ears. I’m still learning efficient ways of doing things within xojo, and trying not to over-complicate things by leveraging dictionaries, arrays, databases, etc - when a plain old globally scoped variable will do the trick. Not that any given method is wrong, there are just lots of ways to skin this cat. I was just trying to automate the creation of these objects, since the point-and-click method is far too cumbersome. I’m a perl guy, so it was easy for me to write what I thought was going to be the input code for the IDE script, it just doesn’t work the way I’d hoped it would.
As the docs say, you need to use SelectProjectItem each time:
[code]If SelectProjectItem(“Window1”) Then
DoCommand “NewProperty”
ChangeDeclaration(“A”, “”, “String”, 0, “”)
End If
If SelectProjectItem(“Window1”) Then
DoCommand “NewProperty”
ChangeDeclaration(“B”, “”, “String”, 0, “”)
End If[/code]
It seems to me that you are trying to apply how you are used to program in Perl to Xojo. In my experience it is usually best to embrace how things are done in a different programing language and framework.
Of course global variables work in Xojo. But in the long term - if your app will grow - it might lead to an unmanageable complexity. All my applications don’t have global variables (except the translation strings and such stuff) - and one of them is a large accounting/ERP system.
There are plenty of non-global variables in my app - it’s just this one group of them that makes sense to be global based on what they are and how I use them. I’ll try using the SelectProjectItem logic shown above and see if this works. Thanks
I know this is a very old (~2014) Topic, but in case someone like me comes along, maybe this will help.
Here’s the code to create a new class, and add 3 properties to it:
// --- Create and Select a New Class ---
DoCommand "NewClass"
PropertyValue("Class1.Name") = "MyClass1"
//--- Create First Property Since Class is already selected ---
//--- Scope ---
// 0: Public
// 1: Protected
// 2: Private
DoCommand "NewProperty"
// Prop. Name Default Type Scope ???
ChangeDeclaration("Prop11", "PUBLIC", "String", 0, "")
//--- For Each Additional Property, Must Reselect Class ---
If SelectProjectItem("MyClass1") Then
DoCommand "NewProperty"
ChangeDeclaration("Prop12", "PROTECTED", "String", 1, "")
End If
If SelectProjectItem("MyClass1") Then
DoCommand "NewProperty"
ChangeDeclaration("Prop13", "PRIVATE", "String", 2, "")
End If