Day 004 - Menus and procedures

Day 4 starts on page 46 of the tutorial. The WinDev 16 tutorial that is - with the official English WD17 release looming I'll be switching over soon. But I imagine the tutorial will remain similar. 

So far I've been creating windows, but none of these serves as the application's main window. I need one with a menu, as the tutorial explains. 

I created a new window and called it WIN_Menu. Dunno about you, but I find I'm beginning to tire of the standard charter approach, as I have an aversion to both all caps and underscores. But I guess I'll stick with it for the tutorial. 

Adding a main menu is easy:

That creates a menu button on the window:

You can add new menu items by right-clicking on the initial (or any other) menu item and choosing Add after or Add before. You add a submenu to any item by choosing Transform to expand a sub-menu.

I transformed File into a submenu, typed in E&xit for the first (and only) submenu item, and then set the properties for that item as follows:

Specify a keyboard shortcut and that text will automatically be added to the window. 

Although I removed my second language from the project, and even closed and opened the project, my second language remains. So just ignore it. 

Note the keyboard shortcut settings to match the text. Also as usual you can use & for the hot key. 

Moving menu items around is a bit limited, as near as I can tell. You can move items up within their own level, but you can't move a menu item to a different menu. 

When you choose an Action for a window you're presented with some standard actions as well as any windows you've defined:

There's also an All the actions button which brings up this more comprehensive list:

Once you've created the menu you can preview it by choosing Display | Display the window or pressing Shift-F9. This is not the same thing as pressing Go to run the window. Displaying just shows the window; none of the code behind the window is running. 

Although you can clearly choose actions for menu options, the tutorial instead explains how to bring up windows using code: Open(windowname) opens a window, and Close(windowname) closes it. 

Close() with no parameters closes the current window. Do so from the main menu and you exit the program. 

The tutorial also notes that you can create menu items programmatically. 

Variables

In WinDev, variables are declared using the 

name is type

syntax. The examples given demonstrate simple types, arrays, multiple declarations, and initial values:

Subscript is int
SupplierName is string
ArrayPrice is array of 10 currencies
I, J, K are int
Counter is int = 120
B1 is boolean = false

Variables can be declared locally or globally. Global variables can be global to the project or global to a window. The tutorial wisely advises against excessive use of globals, and advises that if you want to share data between windows that you pass parameters. 

The usual program flow control statements (If, Switch) are there, along with several kinds of loops. 

Comments are preceeded by // 

Rather than a Self keyword, WinDev has a MySelf keyword. And there's that odd .. notation for object members instead of a single period. 

Local procedures belong to the window in which they are declared and can't be used outside that window. 

Interestingly, global procedures are stored in "sets", and each set is kept in a binary .WDG file. Procedure sets can be shared among projects and among developers within a project. 

Procedure parameters

Procedure parameters can be mandatory or optional. Mandatory parameters must be declared first; optional parameters are defined by specifying a default value for the parameter. 

From the example it appears you don't need to define the parameter type, and this is confirmed in the help. You can force the type in the declaration, but if you don't the type is passed in with the procedure call. I'll be interested to learn more about how this is implemented. 

Defining procedures

You can define both local and global procedures via the Project Explorer.

You can also define global procedure sets right-clicking on Procedures in the explorer and choosing New set of procedures. 

On page 56 the tutorial suggested looking at the WD Get familiar.WDP project, which I found in \Tutorial\Answers\WD Get Familiar.

Next time, strings!