Salesforce

How Do I Create a Simple Program? (Magic xpa 2.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

How Do I Create a Simple Program? (Magic xpa 2.x)

In most programming books, you will find an example of a simple “Hello world!” program. Here are the instructions for “Hello world!” in Magic xpa.

Hint: While you are just starting out in Magic xpa, always remember the F1 Help key! There is a lot of context-sensitive information available just a keystroke away.

Creating “Hello world!” in Magic xpa


  1. Go to the Program repository (Shift+F3), to the spot where you want to create your new program.

  2. Press F4 (Edit->Create Line) to open up a new line.

  3. Type in the name of your program, in this case, Hello World. Magic xpa does not use this name internally, so you can use any naming convention you like.

  4. Press zoom (F5, double-click) to open up your new program.

  5. Because this is a new program, the Task Properties dialog box will open up. You can just escape or click OK; the defaults will be fine for a simple program.

  6. Next you will see your new program. Notice the three tabs at the top: Data View, Logic, and Forms. This is where you will do your coding in Magic xpa.

Creating the Data View

  1. First, let’s set up the data view. Click on the Data view tab. Note that there is already a Main Source line. You can ignore that, because we are not using a data source in this example.

  2. Press F4. This will open up a line.

  3. In the pull-down box, select Virtual. This means we are creating a temporary variable. Tab to the next field.

  4. Give your virtual a name. We called ours Display Field.

  5. Tab twice, to the field that says Alpha. This is the data attribute, which is alpha by default. You can click on the pull-down here to see the other choices. Tab again. Now you will be on the Picture field. Type in 40. This means our alpha field will be 40 characters long. Tab to the property labelled Init:

  6. The Init property is where you will create values that are updated immediately when the task starts, or are recomputed during execution. In this case, we are going to initialize the field to Hello World. Press F5 to zoom to the Expression Rules.

  7. In the Expression Editor, press F4 to open up a line, and type ‘Hello world’ (including the single quotes). Click OK.

  8. The Expression Editor will close, and the number ‘1’ will appear next to the Init: prompt. This means that the Init: is pointing to expression #1. You will also see all or part of the expression to the right of the Init: field.

Hint: For a simple expression like this, you can also just type = in the Init column. This will open up a small box, and you can type the expression there.

And that is all you have to do for this program in the Data View Editor.

Creating your logic


For this program, you don’t need to do anything in the Logic Editor. Magic xpa will take care of most of the housekeeping for most programs, so there is usually not as much explicit logic as you would expect.

What you would be creating here would be certain kinds of field validations, calling other programs. See How Do I Work with the Magic xpa Engine as an Event-Driven Engine? for more details about using logic and events in Magic xpa.

Creating your display

  1. Click on the Forms tab. You will already see a form created, named “Hello World!”. By default it will be named the same thing as your task, but you can rename it if you want. Also, by default, this is the text that will show on the title bar of the window.

  2. Zoom (F5 or double-click) on the Name of the field. Now you will see your display. It is basically an empty window at this point. You can reposition it, or drag the sides of the window to resize it. The properties pane (Alt+Enter) will also show you a lot of ways you can change this window. But for now, we’ll just accept the defaults.

  1. Besides your display, you should see two extra boxes, labelled Controls and Commands. These are palettes you will use while editing forms in Magic xpa. The same options are also available on the overhead menu and via shortcut keys. It is good to get familiar with the options and the shortcut keys.

    If for some reason the Controls and Commands are not showing in the workspace, select View->Form Editor Palettes (also available on an overhead icon). This toggles the palettes off and on.

  1. Click the Variables tab on the Control palette. This will show you all the variables we have in our data view, which in this case is just one.

  2. Click on the variable. The cursor will change to a box, indicating we are selecting an edit field. Click on the form to drop the variable on the form. Note that the field is pasted, and so is the field prompt, which by default is the name of the virtual. If you name your virtuals carefully, you can save time creating your form.



      That’s all you need to do here. Select Options->Save and Close Object to jump back to the Program repository.

      Running your program

      1. Before you run your program, press F8 (Options->Check Syntax). If the program is ok, you will get a message on the prompt line “Program is OK”. Otherwise error messages will appear in the Checker pane. You should always fix the errors before running the program, because as with any programming language, some errors will result in unexpected behavior.

      2. To run your program, select Debug->Run (F7). A new window will appear, running your program as it would appear in the Magic xpa runtime engine. While the program is running, your development environment is locked, in read-only mode.

      3. Here is your Hello world! program. When you exit out, you will be back in the Magic xpa Studio, and you can do more programming and re-test it. This way, you can easily do incremental programming in the Studio.

      4. There is also a full debugger available, so while you are running your program you can see what the Magic xpa engine is doing internally.

      See also

      The Online and Rich Client Samples projects (program TS02 and RTS02)

      Reference
      Attachment 
      Attachment