New to Xojo? Been using it for a while? Either way, here are some secrets that can speed your development. Do you know them already? Do you have some of your own?
Code Completion
When typing code block commands in the code editor, you can press Shift-Return at the end of the line to have it fill in the “End” part of the block. For example, if you start typing an If statement like so:
If value = 123
then you can press Shift-Return after typing “123”, then the code editor will automatically add the “Then”, “End If” and put the cursor between them so you can type your code. This is a great time-saver! This also works with other block commands, such as Select…Case, Try…Catch and While…Wend.
Easy Subclassing
You can drag controls from the Library directly to the Navigator. This creates a new class that is a subclass of the control. You can then drag the subclassed control from the Navigator onto a layout to use it.
You can also right-click on any class in the Navigator and select “New Subclass” which creates a new class with the Super already filled in for you.
Navigator
Collapse all in Navigator by clicking “Hide” then “Show” next to Contents (hover to see this).
You can multi-select items in the Navigator and drag them to other parts of the Navigator, which is useful for organization.
You can even do this with with members of a class, such as properties and methods. For example, you can drag a method (or multiple ones) from a class and drop it onto a new class to move the method.
Auto-Save
You can use an IDE Script to automatically save your project each time you run it. Use the Insert button or menu to add a new Build Step->Script and enter this one line of code:
DoCommand("SaveFile")
Now drag the script onto one of the OS items in the Build Settings and place it before the Build step that appears. This runs the script before each run or build.
Refactoring
When writing code in the code editor, you may end up with a method that is longer than you might like. Generally, 100 lines or so is probably the most you want in a single method. You can easily move a chunk of code to its own method by selecting it in the code editor, right-clicking on it and selecting “Convert to Method” from the menu.
This creates a new method with the selected code added to it (and the selected code removed from the original method). You can then give the method a new name (and possible parameters) and call it from the original method.
Convert to Constant works similarly, creating a new constant with the selected text as its value.
There are also “Wrap” commands to wrap code blocks into If…Then, Do…Loop, While…Wend.
Library
In addition to using the search field at the top, you can click on Library and start typing to quickly highlight a control.
Click the Gear icon to drop down a menu that lets you change how the controls in the Library are displayed. I prefer “Small Icons and Labels” with “Show Group Banners” selected.
Debugging
Use the Break command for conditional breakpoints when debugging. By using the Break command, you can force the debugger to appear when specific conditions are met. For example, this displays the debugger when the value reaches 100:
If counter = 100 Then Break
Break has no effect in a built app, but if you want to ensure the code is not in the built app at all, you can use the DebugBuild constant:
#If DebugBuild Then If counter = 100 Then Break #Endif
One final secret: All of the above items are in the documentation! Read more in the updated User Guide, now available online at the Dev Center.
What are your favorite Xojo secrets? Share them in the comments!