Introduction to REAL Studio

From Real Software Documentation

Jump to: navigation, search

Contents

Introducing Real Studio

Aim
In this lesson, you will learn how to create and run a simple Real Studio application. You will also learn a little of what goes on behind the scenes in Real Studio.

Remember: The Real Studio curriculum project is concerned with teaching you computer science, so we will not be covering Real Studio’s capabilities in detail. There are many other places where you can get that information, starting with Real Studio’s documentation.

Creating the Project

  1. Double-click the Real Studio icon to start the software.
    Real Studio opens the New Project dialog box.
    The New Project dialog.
    You need to choose the type of project that you want to create. The two major choices are a Desktop Application and a Web Application. A Desktop Application runs on any desktop or laptop computer (Windows, Macintosh, or Linux) while a Web Application is a web site that runs “in the cloud”, such as Google Mail. In this set of lessons, you will only be creating a Desktop Application.
  2. Highlight Desktop Application and click Choose.
    Real Studio opens the IDE window for Desktop applications. The Real Studio IDE consists of several editors that are presented in tab panels. The Window Editor is in front. You use this editor to design the screens that your application will use. The application can have many screens and each is created in its own Window Editor.
    The Project Editor is also open and its tab is first but it is behind the Window Editor.
    The Window Editor, in front of the Project Editor.
    You can have more than one such window for a single project, and you can open multiple projects at once if you like, but you will often do all your Real Studio work in just this one window.
    You can work in one window because you can open many different tabs (much as with a tabbed web browser) to view different parts of your project. Because you have just launched Real Studio without opening an existing project, Real Studio creates a new project with some starter items already in the project.
    For now, we will focus only on building the interface for the application using the Window Editor.
    Notice also that the Window1 tab has a close widget on its right side. Closing a tab only closes the editor; all the objects in your program remain until you delete them from the Project Editor. You can always re-open an editor by finding the object you want to edit in the Project tab and double-clicking on it.
    In the center of the Window Editor, you see a blank window, ready to edit. To its left, you will see the Controls list, from which you can drag any of the controls you can add to the window, such as buttons, labels, text boxes in which the user can enter information, and so on:
    The Controls list.

    The pop-up menu above the Controls list lets you switch between Real Studio’s built-in controls, ones you’ve added through Plugins, ones you’ve created yourself, and Favorites.
    We will use only a few of the many controls from this list in our lessons, but we will explain how each of these works as we get to it. Consult the User’s Guide for details on what the other controls do and how to create customized controls of your own.
  3. Drag a Label control into the top left of the window.
    Once you’ve dropped it, drag it around a little. Notice that Real Studio displays guide lines and “snaps” the control to the right spot, to help you place things according to your platform”s User Interface Guidelines[note 1].
    User interface guidelines are available from the following sources:
    * Windows: Microsoft’s User Interface guidelines at: http://msdn.microsoft.com/library/default.asp?url=/library/enus/dnwue/html/welcome.asp
    *Macintosh: Apple Human Interface guidelines:
    http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/
    *Linux KDE Desktop: KDE user interface guidelines: http://developer.kde.org/documentation/design/ui/
    KDE is one of the most popular Linux desktops and is used by default in several major Linux distributions. However, there are others. Linux supports a greater degree of desktop customization than Windows or Macintosh.
    The Properties pane, which is on the right of the Window Editor, lets you manage the settings for the control that is currently selected in the window or the window itself:
    The The Properties pane for the Label control.

    Most of these settings are obvious; don’t worry for now about those that aren’t. Click on the Text: property and change it to read ‘Name:’ (without the quotes). Note that you can click in an area of the window that doesn’t contain a control to manage the properties of the window itself. Note also that you can resize the window when it is selected.
  4. Drag a TextField control into the window to the right of the Label control.
  5. Change its Name: to “UserName” (one word, no spaces, and no quote marks).
  6. Drag a PushButton control into the bottom right corner of the window:
    Horizontal and vertical guidelines appear as you drag it toward the corner of the window.
  7. Change its Caption property to “Greet Me”.
    You’ll probably need to make the button a little wider to get its label to fit. Note that you can change the location and size of the things in the window using the same techniques you would use in any drawing program.
  8. Double-click on the PushButton.
    This switches the Window Editor from editing its layout to editing its objects. You can also switch between the Layout editor and the Code Editor by clicking the unselected Edit Mode button. In this illustration, the Code Editor mode is selected.
    The Edit Mode buttons.

    The Edit Mode buttons switch from the layout editing mode (highlighting the right side of the widget) to the code editing mode (highlighting the left side). You can also switch between the two by clicking on the control. On the Windows platform, the selected mode is depressed instead of highlighted.
    The Code Editor lets you see all the code you’ve added directly to the window or the controls in it (we will see later that usually, some or even most of the code governing the behavior of the window and the controls will be elsewhere, but don’t concern yourself with that for now). The Code Editor opens to the most likely Event for the control you just double-clicked on.
    The Code Editor pane.

    Note how the Code Editor lets you edit the program code for every control in the window, as well as other things belonging to the window, through the browser to the left of the code editing area. On Windows, you expand items by clicking the plus signs and, on Macintosh and Linux, you click disclosure triangles. Try clicking on some of the little plus signs or disclosure triangles in the browser and you’ll see.
    For now, you only need to understand that all the controls in the window can contain Real Studio code to tell them what to do when particular things happen. In the example shown, the button has been told what to do when it is clicked on (that is, when its Action event occurs). Type in the code exactly as you see it in the picture:
    MsgBox UserName.Text

    As you start typing the word MsgBox, Real Studio will try to anticipate what you are typing, and will fill in the rest of the word:
    Code completion.

    Whenever Real Studio does this, you can press the Tab key to accept Real Studio’s highlighted suggestion, or to choose from a list if there is more than one possible way to complete what you have typed so far.
    Note that there is only one space in that line, between MsgBox and UserName.Text (in particular, only a period and no space between UserName and Text).
    A note: Real Studio program code is not case-sensitive. This means you can use uppercase, lowercase, or any mixture of these, and things will work just fine. And one final thing: If you click in the grey area to the left of the line of code, you will see a red dot appear. This sets a breakpoint in your code. Until we discuss breakpoints in Lesson 3, just click on the red dot and it will go away again.
  9. Save your project, just as you would save a file in any other program.
    If you run the program after modifying it and without saving it, Real Studio automatically saves a hidden copy, just in case something goes wrong while running the program (if ral Studio does crash on you[note 1], just fire up Real Studio and it will offer to restore the hidden copy for you). But it is a little easier if you remember to save your projects yourself. Besides, we’re going to be using this project again — so make sure you remember where you put it.
  10. Click the Run button in the toolbar:
    The Real Studio Toolbar.

  11. Real Studio will open a new Run tab, which will show you the progress as Real Studio compiles your application.
    It also lets you interact with your program while it runs through Real Studio’s debugger. We will discuss the debugger in Chapter 3.
    If Real Studio is unable to compile the application, it shows you the errors it encounters that prevented it from compiling. If Real Studio shows you any errors, it will switch back to the Run tab and highlight the line where the error occurred. Check what you typed against what we have above, fix the problem, and try again. When the application has no errors, Real Studio will compile and launch the program in its own window. Meanwhile, the Run tab in the IDE lets you monitor execution in the debugger.
    Your first Real Studio program.

    When the program runs, type something into the TextField box, and click the “Greet Me'” button. It will display exactly what you typed, in a dialog box. Click OK to close the dialog box, then choose Exit from the File menu (Quit on Mac OS X and Linux). This will return you to Real Studio’s programming environment (in fact, the program and Real Studio are just two separate running programs, so you can switch between the two at any time, just as you can between any programs on your operating system).
    A program consists of lines of code. Now let’s see how that worked.
  12. Quit out of the test application and choose Language Reference from the Help menu.
    This will open Real Studio’s Help system, which provides fairly complete information about Real Studio’s programming language and its class library[note 2].
    The Language Reference window.

A program consists of lines of code

A Real Studio program consists of one or more lines of code. Each line tells the computer to do one thing.

Those lines can take a few different forms, but the most common is like the one in this program: it consists of a command (in this case, MsgBox) at the beginning of the line, usually (but not always) followed by a space and then one or more pieces of information needed for the command to make sense. These pieces of information are called the arguments to the command. In this case, the MsgBox command needed a single argument, which provides the text for it to display.

Any particular line of code can be caused to take effect (we say the code is run or executed) in any of a fair number of ways. In this case, the code formed an event handler for a control, so it ran when an event occurred (in this case, when the button was clicked). By clicking on the disclosure triangles on the list of objects on the left side of the code editor that events are provided for just about anything happening you can think of (the mouse button going up over the object, the mouse button going down over the object, the mouse pointer moving over the object, something being dropped onto the object, and so on). We will use many of these events in later projects. Again, there is full documentation on all of the events available in every type of control, in the built-in Language Reference.

A program also consists of objects with properties

The string (meaning the words) we wanted the MsgBox command to display has to be obtained from a property of the object in the window called UserName (remember when we set the name of the TextField?). The term property here means pretty much what it means in the real world: It is an attribute of some object (in this case, the text that the user entered into it). To fetch whatever a property is at the moment, we put the name of the object, a period, and then the name of the property (all with no spaces, as in UserName.Text in our program). When Real Studio runs a command and sees an argument written like this, it looks up what the value of the property is at the moment and then uses that value to complete the command.

If this is confusing right now, don’t worry too much; we’ll be discussing how a line like that works in some detail in the next lesson.

Behind the scenes: What is a Compiler?

It is helpful to understand a little of what is going on when you click Run.

Computers are immensely complex arrangements of millions upon millions of transistors in very complex circuits. These circuits are designed so that the things they can do include such tasks as storing and retrieving numbers very quickly, and treating those numbers not just as information, but also as simple instructions to compare other numbers, perform calculations on those numbers, move them around, and so on. It is possible to instruct the computer to do anything it is capable of, using these simple numeric instructions (creating programs this way is called writing machine code), but this is immensely inefficient and frustrating for people to do. Nevertheless, programs written in this way can generally be made to run about as fast as the computer is capable of. When speed is important, people will write even quite complex code this way: important parts of computer games, for example, are often written in machine language.

Two major ways have been devised to make it more efficient for humans to program computers. Both involve devising an artificial language that provides a more expressive, human-friendly way of representing what the computer should do[note 3]. The difference between the two approaches lies in how the computer winds up doing what this ’high level’ language commands:

  • An interpreter just reads the code and immediately does whatever the program commands; while
  • A compiler reads the code for the program in the high level language and produces a machine language program that does the same thing.

Each is suitable for a different purpose. For various reasons, interpreted programming languages tend to be a bit easier for humans to write, but the programs they run are considerably slower than compiled programs. Compiled programming languages usually impose a few more restrictions on the programmer, in order to let the compiler produce faster code. Modern computers are so fast that the easier interpreted programming languages are better for simpler tasks because they make it as easy as possible on the programmer.

Real Studio is a compiler, but the Realbasic language is a very friendly one, particularly for a compiler. Nevertheless, there are a few restrictions imposed on you as a programmer, in order to permit Real Studio’s compiler to produce faster machine language programs. In practice, not only do these restrictions result in fairly fast programs, but in complex programs, most of these restrictions also help to catch logical errors.

A Final Note

Finally: this course is a course in computer science that happens to use Real Studio. It teaches you just enough about Real Studio to learn the computer science. You should certainly read about more of Real Studio’s features in the User’s Guide and other documentation. In particular, you should probably read Chapter 2 of that guide, which describes more about how the IDE works, right now.

References

Notes
  1. Any programming tool of Real Studio’s complexity will inevitably “crash” from time to time. This is both because no program of any complexity is ever completely bug-free, and also because Real Studio gives you access to the system in such a way that it can’t always protect you from crashing your program when you do something wrong. Don’t be too alarmed about this; it shouldn’t happen very often.
  2. A class library is a collection of ready-made tools. All the items in the Controls list, along with the other objects listed in the Language Reference form Real Studio’s class library.
  3. Representing the program in this way provides another benefit as well: the program is less tied to the particular machine language of a particular type of computer. This is why you can take a Real Studio program that runs on a Macintosh, and (using the Professional version of Real Studio) compile that same program to run on Microsoft Windows, with minimal or no changes, even though the machine language for the two computers is very different.

Next Chapter

Personal tools