Tutorial Web Xojo
Tutorial Web Xojo
Tutorial
2015 Release 2
Xojo, Inc.
Chapter 1
Introduction
Section 1
This Web Tutorial is for people who are new to programming and new to Xojo. It is
an introduction to the Xojo development environment and will lead you through the
Copyright
All contents copyright 2015 by Xojo, Inc. All rights reserved. No part of this
document or the related files may be reproduced or transmitted in any form, by
any means (electronic, photocopying, recording, or otherwise) without the prior
written permission of the publisher.
Trademarks
Xojo is a registered trademark of Xojo, Inc.
This book identifies product names and services known to be trademarks,
registered trademarks, or service marks of their respective holders. They are used
throughout this book in an editorial fashion only. In addition, terms suspected of
being trademarks, registered trademarks, or service marks have been
appropriately capitalized, although Xojo, Inc. cannot attest to the accuracy of this
2
Section 2
Presentation Conventions
The Tutorial uses screen snapshots taken from the Windows, OS
X and Linux versions of Xojo. The interface design and feature
set are identical on all platforms, so the differences between platforms are cosmetic and have to do with the differences between
the Windows, OS X, and Linux graphical user interfaces.
Bold type is used to emphasize the first time a new term is
used and to highlight important concepts. In addition, titles of
books, such as Xojo User Guide, are italicized.
ShowURL(SelectedURL.Text)
Section 3
Getting Started
If you havent done so already, now is the time to start Xojo.
Web and Console). For this Tutorial, you are building a web
application, so click on Web.
Section 4
Workspace
Xojo opens the Workspace with the default window for your
Layout Editor: The center area is the Layout Editor. You use the
Layout Editor to design the user interface for the windows in your
Layout Editor.
because you haven't yet added any user interface controls from
the Library.
Library: The area on the right is the Library and shows the
controls and interface elements that you can add to a window or
to the project. You design the window by dragging controls from
the Library to the window. You can also add a control to the
window by double-clicking it.
You can change how the controls display in the Library by
clicking the small gear icon
setting.
Navigator: The area on the top left shows you all the items in
Note: If the Library is not visible, click the Library button on the
selected), the App object and the Session object. You use the
Navigator to navigate within your project.
selected control. This area of the Main window is shared with the
Library. You can show the Inspector by clicking the Inspector
button on the toolbar. The Inspector shows information about the
selected item in the Navigator or Editor. The contents of the
Inspector changes as you click on dierent items. You change an
Inspector value by entering a new value in the field to the right of
the field label.
Section 5
You enter tasks in the text field and click Add to add them to the
list. You can click on individual tasks in the list to delete them or
shown.
Chapter 2
Designing
the User
Interface
Now you will design the user interface for the Task
Manager web application.
Section 1
Task List
2. Resize the Listbox:
You are now going to add a Listbox to the web page. The
Listbox is used for storing the tasks.
10
Section 2
Buttons
web page near the bottom-left corner.
The Delete button removes tasks from the Listbox, the Add
button adds tasks to the Listbox and the Complete button marks
tasks in the Listbox as completed.
4. Your web
page now
looks like
this:
11
Section 3
Text Field
Add the Text Field
The Text Field is where the user types the Task to add to the list.
Listbox.
12
Section 4
Properties
You can toggle between
What is a Property?
A property is a value of a class. Changing property values
For this project, you want to change various properties for the
web page and its controls. Some of the things you need to do
Linux.
are:
Rename all controls (and the web page) so that they describe
Inspector
The Inspector is used to change the window and control
properties. It shares the same area on the right of the main
window as the Library. In order to show the Inspector, click the
Inspector button on the toolbar.
13
Section 5
You need to change the Name and Title properties of the web
page:
1. First, in the Layout Editor, click on the title bar of the web
page to select it. The Inspector pane now shows the
properties for the web page.
2. In the Name field (located in
the ID group), change the
14
Section 6
ListBox Properties
on the Layout Editor toolbar (
The Listbox is where the tasks that your user enters are
15
Using 100,* tells the Listbox that the first column should
always be 100 pixels wide and that the rest of the columns
share the available width.
6. Lastly you need to make
changes to the locking so that
16
Section 7
Button Properties
the web page resizes.
The three buttons are used to perform actions. You need to
change the following properties for each button: Name, Caption
and Locking.
Delete Button
The Delete button is used to remove tasks from the TaskList.
1. First, in the Layout Editor, click on the Delete button to select
it (this is the button directly below the Listbox). The Inspector
now shows the properties for WebButton.
2. In the Name field (located in the ID group), change the name
from Button1 to DeleteButton. Press Return to see the
name change in the Navigator.
3. In the Caption field (located in the Appearance group), change
the name from Untitled to Delete. Press Return to see the
name change on the button in the web page.
4. Now you need to make changes to the locking so that the
Delete button stays on the right side of the web page when
Add Button
5. The Add button is used to add the task entered in the
TextField to the Task List.
1. In the Layout Editor, click on the Add button to select it (this is
the button on the far left of the web page below the TextField).
The Inspector now shows the properties for PushButton.
2. In the Name field (located in the ID group), change the name
from Button2 to AddButton. Press Return to see the name
change in the Navigator.
17
4. Now you need to check the locking so that the Add button
stays on the bottom of the web page when the web page
resizes.
right.
Complete Button
The Complete button is used to mark a task as completed.
In the Layout Editor, click on the Complete button to select it
(this is the button directly below the TextField on the right).
The Inspector now shows the properties for WebButton.
In the Name field (located in the ID group), change the name
from Button3 to CompleteButton. Press Return to see
19
Section 8
top is unlocked.
page resizes.
Section 9
21
Chapter 3
Adding Code
Section 1
Add Button
Adding Code to the Add Button
The Add button adds tasks to the list. The code you add to the
labelled Add.
ObjectName.PropertyName. This is
programming.
The syntax looks like this:
TaskField.Text
TaskList.AddRow("", TaskField.Text)
24
Section 2
Complete Button
Adding Code to the Complete Button
When the user clicks the Complete button, the selected task in
ListIndex property.
like this:
1. On the web page, double-click the CompleteButton control,
labelled Complete.
TaskList.Cell(TaskList.ListIndex, 0) = ""
4. Run the app and add a few sample tasks. Now click on a
task and click the Complete button. A checkmark appears in
the Completed column.
25
Section 3
Delete Button
Adding Code to the Delete Button
The Delete button is used to remove tasks from the list. The
code you add to the button needs to determine the selected row
TaskList.RemoveRow(TaskList.ListIndex)
in the Task List and click the Delete button. The task is
the other buttons, you want to use the Action event handler
26
Section 4
Debugging
Finding Bugs
Although your app works just fine, there are a couple of lingering
OutOfBoundsException.
28
Chapter 4
Next Steps
Section 1
30
Section 2
Improvements
3. Select DeleteButton, labeled Delete. In the Inspector, turn
Button Usage
Did you notice that there are times when the buttons in Task
Manager probably should not do their action? For example, the
Complete button should not try to mark a task as completed if
4. Now you will add code to enable the Add button when there is
text in the Task Field.
one is not selected. Right now you can click it, but nothing
happens. Also, you are not going to want to add a task to the list
if nothing has been entered in the task field.
handlers. In
this case,
we want to
Appearance group) to O.
disable
AddButton
when there
is no text in
the task field
31
click OK.
8. Add this code:
Else
AddButton.Enabled = False
CompleteButton.Enabled = True
End If
Else
DeleteButton.Enabled = False
CompleteButton.Enabled = False
End If
become disabled.
Similarly, when you click on a row in the Task List, the Delete
and Complete buttons become enabled.
33
Section 3
want to share it with the world. Although you can run a web
Deployment Options
34
even after the web page has finished loading. This is a result of
the method used by the web server to communicate with your
web application.
Because a CGI deployment uses your existing web server
software, you do not have to specify a port when accessing your
web application. A typical URL looks like this:
http://www.mywebsite.com/cgi-bin/mywebapp.cgi
Deployment
Because of the wide variety of servers and their individual
settings, the specifics for deploying a web app to a server is
beyond the scope of this tutorial.
But in general, the steps to deploy a web application to a Linux
server are simple:
1. Compile your web application for Linux.
2. Connect to your web server using FTP.
3. Upload your web application (including the Libs folder)
4. Verify that the execute flag is still set for the files that you just
uploaded. Some FTP clients have been known to change this
flag during upload.
35
Section 4
All Done!
Congratulations
You have successfully completed the Web Tutorial and now have
a fully functional application.
To continue on your journey of learning Xojo, you should next
move on to the User Guide, which covers Xojo in its entirety.
You will also want to refer to the Language Reference, which
covers the specifics of language elements, classes and other
details of Xojo.
36