Well guys, here’s proof that it CAN be done – that you can create classes from code.
[h]IDE Script to Create Class[/h]
[code]
Var LF As String = Chr(10)
// — 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
//— Create Method —
If SelectProjectItem(“MyClass1”) Then
DoCommand(“NewMethod”)
ChangeDeclaration(“myMethod11”, “x As Integer, y As Integer”, “Boolean”, 0, “”)
End If
//— Compose the Method Text —
Var methodStr As String
methodStr = “” _
- LF + “//— Added from IDE Script —” _
- LF _
- LF + “Var z As Boolean” _
- LF + “z = (x > y)” _
- LF + “Return z”
//— Set the Method Text in the IDE —
Text = methodStr[/code]
[h]Results[/h]
I’m sure some of you will look at this script and think “that’s way too much trouble to use”. If so, then you don’t understand how some programmers work. Here’s a clue: I would never actually type out all of that code.
If you don’t understand the benefit of looking at class, property, and method definitions in code, well you can keep using the “easy” way of point and click. I find lots of value in understanding the classes by viewing in code. And much of it is repetitive, so copy/paste works well. Plus I have tools like Typinator and Keyboard Maestro that can highly automate this kind of stuff.
When I first started designing apps a hundred years ago, I was told by one of my mentors that you should always design your apps to work well with both the mouse, and keyboard only. Some of us prefer to keep our hands on the keyboard as much as possible, because we find that’s most productive for us.
I hope I have helped some future new Xojo user who, like me, has been pulling his/her hair out trying to figure out how to create classes from code. And also maybe I have shown a few of you old hands another way to do things. Choose the way that works best for you.