Web Tutorial
From Real Software Documentation
Real Studio Web Tutorial
Welcome to the Real Studio Web Tutorial!
This Tutorial is for people who are new to programming and new to Real Studio Web Edition. It is an introduction to the Real Studio Web development environment and will lead you through the development of a real web application.
The Web Edition is a feature of the Web or Enterprise editions of Real Studio. Users without appropriate licenses can try out the Web Edition in Demo mode. The Demo mode does not save your projects and runs them for only a brief period. If you do not have an Enterprise or Web license, then you can learn about the Desktop Edition in its own QuickStart and Tutorial.
It should take you about an hour to complete this tutorial.
Note: If you have experience with other versions of the BASIC language or other programming languages, you’ll want to check out the User’s Guide. In the Language Reference, check out the “Web” theme for the commands that are specific to the Web Edition.
Presentation Conventions
The Web Tutorial uses screen snapshots taken from the Windows, Macintosh, and Linux versions of Real Studio. 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 Windows7/Vista Aero interface, the Mac OS X Leopard interface, and the Linux Ubuntu distribution. Of course, the Web application that you will build is intrinsically cross-platform.
- Italic 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 Real Studio User’s Guide, are italicized.
- When you are instructed to choose an item from one of Real Studio’s menus, you will see something like “choose File ↠ New Project”. This is equivalent to “choose New Project from the File menu.”
- The items within the parentheses are keyboard shortcuts and consist of a sequence of keys that should be pressed in the order they are listed. On Windows and Linux, the Ctrl key is the modifier; on Macintosh, the ⌘ (Command) key is the modifier. For example, when you see the shortcut “Ctrl+O” or “⌘-O”, it means to hold down the Control key on a Windows or Linux computer and then press the “O” key or hold down the ⌘ key on Macintosh and the press the “O” key. You release the modifier key only after you press the shortcut key.
- Something that you are supposed to type is quoted. Some steps ask you to enter lines of code into the Real Studio Code Editor. They appear in a shaded box:
When you enter code, please observe these guidelines:
- Type each printed line on a separate line in the Code Editor. Don’t try to fit two or more printed lines into the same line or split a long line into two or more lines.
- Don’t add extra spaces where no spaces are indicated in the printed code.
Whenever you run your application, Real Studio first checks your code for spelling and syntax errors. If this checking turns up an error, Real Studio will direct your attention to the line of code that is causing problems. Check the line against the printed line. The Web Tutorial includes troubleshooting sections that help you handle syntax errors.
Getting Started
You’ll build an application that manages URLs and email addresses. A URL (which stands for Uniform Resource Locator) is the address of a web page that you type into the Address area in your web browser. This application will launch your default web browser application and display the web page that you entered. The following illustration shows a URL in an internet browser’s Address area:
If you enter an email address instead of a URL, the application will launch your email application, create a new blank email, and enter the address into the “To” box. The next illustration shows how to enter an email address into a browser’s Address area.
When you are finished, the application will look like this.
In the following illustration, the labels indicate the types of controls that were used in creating the application. The application uses three types Real Studio controls to do most of the work for you:
- A WebListBox is the type of control that holds scrollable lists. It can hold both single and multiple-column lists and scroll horizontally and vertically.
- A WebTextField is the type of control that holds a single line of text.
- A WebButton is a standard pushbutton. It is most often used to initiate an action (as it is here).
You use the TextField to enter the URL or email address you want and then click the Connect button. To save it in the list, you click the Add button. To select a URL in the ListBox, highlight it in the list and then click Connect. If you don’t need the URL any more, highlight it in the list and then click the Delete button.
Creating the Interface
If you have not already done so, double-click the Real Studio application icon. In a few moments, the New Project dialog box appears. The first thing you need to do is choose what type of project to create. Your choices are:
- Desktop Application: An application with a graphical user interface that runs on the Macintosh, Windows, and Linux operating systems.
- Console Application: An application with no graphical user interface that runs on one or more of the desktop operating systems.
- Web Application: An application that is deployed on the web and served to end users by a web server such as Apache.
|
The IDE uses a tabbed interface to display multiple editors in the same window. Notice that two tabs are open. The Web Edition displays the Web Layout Editor as the top panel in the IDE. You switch among the editors by clicking on the Tabs in the Tabs bar. The first tab for the Project Editor is already open. We will get to the Project Editor later (each type of project has its own Project Editor.) Your first task is to build the interface with the Web Layout Editor.
The initial view shows a Web Layout Editor for the default WebPage. A WebPage is analogous to a document window in a Desktop application.
The editor for WebPage1 is shown in below.
The Web Layout Editor is divided into three panes. The pane on the right is the Properties pane and it shows the properties of the selected item in the WebPage Editing area. In this illustration, the WebPage is selected, so the Properties pane shows the properties of the web page.
The center pane is the WebPage Editing area. It is where you design the page. In this illustration, the page is blank because you haven’t added any interface items yet. It shows only a default page.
The pane on the left is the list of controls that you can add to a WebPage. The Controls Pane shows the complete list of built-in Web interface elements that can be added to a WebPage. It contains items for the WebListBox, WebTextField, WebButton, and many more. You add a control to a WebPage by dragging it from the Controls Pane to a location on the WebPage.
In the first exercise, you’ll add a ListBox seen in the final version of the application.
|
Your application’s interface is now complete!
It should look as shown below.
Before going any further, save the project.
- Choose File ↠ Save (Ctrl+S or ⌘-S) and name it “URL Manager”.
At this point, you can actually try it out. Of course it won’t do anything since we haven’t told any of the interface elements what to do.
- Just for fun, click the Run button in the Main Toolbar.
Real Studio builds the application and opens it in your default web browser.
The first version of the application should look like this:
In this state, the Buttons work — that is, you can click them and they highlight — but they don’t do anything because we haven’t told the Buttons what to do when they’re clicked. You can enter text into the TextField — but it doesn’t go anywhere because there are no instructions to process this text. And the ListBox is all set to display and scroll items but we don’t have any way to get text into the ListBox yet.
|
Giving Objects Meaningful Names and Labels
You’ve already noticed that all the Buttons use the default label “Untitled.” They also have default names like Button1, Button2, etc. Before getting too far into the project, we should give the objects meaningful names and labels. You refer to the object’s names in your Real Studio code and, of course, the labels are presented to the user. You should give each object that you refer to in your code a meaningful name at the start of the project.
|
Making the URL Manager Do Something
Now that the interface is designed and its appearance is touched up, it’s time to make the controls do their jobs. We’ll start with the Connect button. You specify the action that a button carries out by writing some code that becomes a part of the button.
|
Since the TextField is named “SelectedURL”, you might think that we could write:
but that won’t work because “SelectedURL” is the name of the object itself. It has lots of properties — like its position in the window, whether it takes several lines of text or just one, whether it can accept styled text, and so forth. If you use “ShowURL SelectedURL”, Real Studio would have no idea what you mean. Besides, the ShowURL command only accepts a text string, not a control. When you need to refer to one of an object’s properties, you write the name of the object, followed by a dot, followed by the name of the property. In other words, you use this syntax: objectname.propertyname. It’s sometimes called “dot” notation. In this case, the TextField is named “SelectedURL” and the TextField property that we want is its “Text” property. This means the following expression accesses the contents of the TextField:
That is, “SelectedURL” is the name of the object and '“Text” is the name of the object’s property that we need.
|
If the Application Doesn’t Run
If Real Studio was unable to launch the debugging application, it’s because it couldn’t recognize a term you entered into the Code Editor. For example, if you misspelled either “ShowURL” or “SelectedURL”, Real Studio stops and points out the term it doesn’t recognize. Instead of compiling and launching the application, it opens a new “Issues“ tab in the IDE. It has one line per issue. For example, the following shows a spelling error.
The misspelled term is highlighted. Double-click the line to go to the editor with the error. In this case, Real Studio displays the Code Editor for the ConnectURL Action event, show below. The line that contains the error has a bug icon to its left.
Since it can’t find an object called “SelectURL,” it can’t create the application for you. Real Studio knows it would never be able to figure out what to do when a user clicks the Connect button. Be sure you’ve renamed the controls as described and referred to their correct names in the Code Editor. You’ll also get this error if you wrote “ShowURL SelectedURL” and left off the name of the property that contains the contents of the TextField.
Another possibility is that you used the correct name in the Code Editor but did not rename the TextField using the Properties pane as shown earlier. In that case, the statement in the Code Editor ought to work, but there is no object named “SelectedURL” in the application. If you get an error message, start by checking the highlighted term. Now, we’ ll make the other controls do their jobs.
The Add Button
The Add button is supposed to take the text in the TextField and add it to the end of the list in the ListBox. That’s easy.
|
Note: A method is a command that performs an action. Technically, ShowURL is a “global method” because it isn’t attached to any particular object. It can be called by any object that can call a method. We just happen to be calling it from a Button. (We could, for example, design the application so that ShowURL is called when the user chooses a menu item instead of clicking a button.)
Just as objects can have properties (like their name, size, position, and label), they can also have their own methods. AddRow is also a method but it “belongs” only to ListBoxes. It has a specialized action that only makes sense when applied to lists in ListBoxes.
The Delete Button
The Delete button removes the selected item in the ListBox. It’s also pretty simple.
|
In this case, we are calling the built-in RemoveRow method of the ListBox control. Instead of text, it needs the number of the row (line) to delete. The ListIndex property contains that number, so we pass that number to the RemoveRow method.
Note: If you place the insertion point in the RemoveRow term, the Tips bar will say that RemoveRow requires that an integer be passed to it.
The ListBox
The ListBox itself has the job of copying the item the user selects into the TextField so the user can connect to that URL or email address. You can do this by writing an assignment statement that runs when the user highlights an item in the list.
In order to do this, you need to get the item that the user has selected in the ListBox. You can get this text, but the process uses two of the ListBox’s properties.
First, the property “List” is the list of all the items in the ListBox. You need the one that the user highlights, not all of them.
The seond property is the number of the selected item, not its text. Real Studio determines which one is selected for you and you can use it to get the text of the selected item. The number of the selected item is in the ListIndex property. The first item is numbered zero. (Thus, this is called a zero-based array.)
The List property needs only the number of the selected item. You get that information from the ListIndex property and hand it off to the List property to get the text of the selected item.
The expression as a whole gets the text of the selected item and assigns it to the Text property of the TextField. It is:
|
Testing the Application
That’s the basics of the application. Now it’s time to test out all these features. Before you run your project again, you can ask Real Studio to check the project for errors or ways to optimize your application. You use the Analyze Project command. Analyze Project uses Real Studio’s compiler to review all of your code and identify any coding errors. It also offers suggestions on how to improve your application.
|
The application looks the same as it did, but all the controls work! For example, enter “http://www.realsoftware.com” into the TextField and click the Add button. Add a few other URLs to the ListBox in this manner and then highlight one in the ListBox to move it to the TextField.
You can:
- Enter a URL into the TextField and connect to the site using your default web browser.
- Add the URL to the ListBox.
- Select any URL in the ListBox to copy it into the TextField.
- Delete the selected URL in the ListBox.
If you want to send an email, enter it in the following way: mailto: username@domain.com
Using Autocomplete
One way to avoid using incorrect terms is to take advantage of Real Studio’s “autocomplete” feature. As you type, Real Studio tries to guess what you are typing. If you type the first few characters of a Real Studio language object — either built-in or a variable, method, or property that you created — it shows its guess in light gray type. If the guess is correct, press the Tab key to complete the entry.
If there is more than one possibility, Real Studio displays a contextual menu when you press Tab. Here is an example:
The user has just typed “ListURL.L” and pressed the Tab key. Real Studio displays a contextual menu with all the possible terms that complete the expression. Use the Up and Down arrow keys to navigate through the list and then press the Enter key (Return on Macintosh) to select the highlighted term.
The small icons to the left of the term tell you what type of object it is. In this case, the checkmarks indicate that the items are boolean properties and the 1’s indicate that they are integer properties.
If the Application Doesn’t Run
This section introduces the If…Else…End if statement. The Code Editor automatically indents the code within an If statement to make it easy to check your code. Be sure that your code is indented as shown in the instructions. Be sure there is an “End If” statement for each “If” and you didn’t type “Endif” instead of “End if”. Capitalization doesn’t matter, but the space between “End” and “if” does. Also, check that each line that begins with an “If” statement ends with “then”. Also, you should not leave a blank space between the double quote marks or between the less than and greater than signs.
Building A Standalone Application
Now that you have a finished version of the application, you’re ready to create a standalone web application. The standalone version of the application is ready to be deployed as a web application.
The Enterprise and Web versions of Real Studio can create standalone Web applications from any desktop platform. The Personal and Professional versions of Real Studio build demo Web applications. A demo version is fully functional but quits automatically after five minutes and cannot be saved as a project.
You can build a Web application that is served by any desktop platform that is supported by the Desktop Version. By default, Real Studio builds for the platform that you are currently running. If you want to cross-compile for another desktop platform, you can make that choice by choosing Project ↠ Build Settings. The following dialog box appears:
This dialog box has two panels. On the General panel you choose the platform from which the Web application will be served. You must configure your Web server to work with this app.
On the Web panel, you choose the type of Web application that you want to be served. It can be a CGI or Standalone HTTP application. You must configure your web server to serve the type of application that you build.
The choices are shown in the Web panel of the Web Settings dialog box.
Deploying the built Web application requires that you configure your Web server. This is beyond the scope of this Tutorial; Chapter 15 of the User's Guide contains instructions for a configuring an Apache server running on any platform and instructions on how to configure Microsoft Internet Information Server 7 (IIS) on Windows.
Building a stand-alone version of your project as an application couldn’t be easier than it is in Real Studio.
|
What’s Next
The Web Tutorial shows how easy it is to develop a simple Web application. But there is much more to Real Studio. The second Real Studio Tutorial builds the URL Manager as a Desktop application. You will see the same Integrated Development Environment, but the design and layout tools are for building cross-platform Desktop applications.
Real Studio is a fully object-oriented development system. With it you can create classes (reusable objects) that encapsulate custom functionality. You can add them to the project so that they can be reused in many places in the project and save them to disk. In the User’s Guide, you will learn about the object-oriented development system in detail. The Language Reference is a comprehensive listing of all the programming elements in the Real Basic language.
Also, be sure to check out the example projects that ship with Real Studio and the Real Studio web site at http://www.realsoftware.com for other tutorials and how-to’s.




