A working solution - Stage 1

Open the IDE to get a default Form.

Designing the outline

Give the Form a sensible name - I suggest "Viewer".

I suggest making the Caption "Text Viewer" to reflect the first intention.

I also suggest positioning the form in the centre of the screen - set the "Win Position" Property to "Middle Center".

The Menu Bar

We shall now add a menu bar with a menu and two menu items.

You introduce a menu bar by opening the "Menu Editor" from the "Editors" menu. A design dialogue is displayed. First add a menu - here "File" by clicking the "Add Menu" button. At this point a caption and menu name are both suggested. If desired replace with your own - I enter "&File" and "Menu_File", respectively. The "&F" indicates that the "Alt-F" keystroke combination will work.

We add menu items in a similar fashion. Clicking the "Add MenuItem" button inserts an entry underneath our "File" Menu and again suggests caption and name, which I have changed to "&Open" and "MenuItem_Open" respectively.

Repeat the process to add an "Exit" menu item, as "E&xit" and "MenuItem_Exit". Then press the "OK" button to return to the main designer window.

Event Handlers

The next task is to determine the event handlers for each of the two menu items. Let's do the easier first.

First go into the "Code Editor" (I'll leave how as a little challenge!) and find the "W32Click" set of events. Choose "MenuItem_Exit" from the list. You should now be editing the "MenuItem_Exit_onClick" procedure. First think what you want to happen when the user selects this option! You want the application to close, which can be effected by closing the top-level window - here the "Viewer" Form. So enter closeWindow(Viewer) into the procedure.

I suggest you test what you have so far before going on!

Make sure you are back in the "Code Editor" and in the right procedure for the "Open" menu item: the "MenuItem_Open_onClick" procedure. Again rehearse what you want to happen before starting coding. We want to initiate the "Open File" Dialog and accept the user's selection. If this is a valid file then we want to open the file, read its contents and display them on our Form. We'll do all these in the easiest possible way for now and then consider better ways as we develop the application further.

I suggest adding a multi-line edit to the Form and placing the file's contents in this control. So we now add the Control to the design. I have named it "TextArea", have made its Caption blank and have opened up the area covered so that it sits nicely inside the Form's area.

The "Open" Menu Item

The steps are as follows:

Try it out!

Now try it out on different files. As you use it think about the ways in which we might make the Viewer work better.

With these thoughts in mind, now let's look at Stage 2.