issue112:tutoriel2
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue112:tutoriel2 [2016/08/29 14:05] – créée auntiee | issue112:tutoriel2 [2016/09/02 15:20] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | In this series of articles, I will be building a text-based application with Free Pascal, using its text-based interface for user interaction. This will be combined with other, more modern, technologies such as database access using SQL and Web access with HTTP. The final aim of the project is to demonstrate how Pascal can be used to build a modern application, | + | **In this series of articles, I will be building a text-based application with Free Pascal, using its text-based interface for user interaction. This will be combined with other, more modern, technologies such as database access using SQL and Web access with HTTP. The final aim of the project is to demonstrate how Pascal can be used to build a modern application, |
- | In the first part of this series we installed the required compiler software and developer’s interface. We compiled a simple console-based program and a first Free Vision application. In this second part we will be tuning our Free Vision interface and making it respond to commands. | + | In the first part of this series we installed the required compiler software and developer’s interface. We compiled a simple console-based program and a first Free Vision application. In this second part we will be tuning our Free Vision interface and making it respond to commands.** |
- | Fleshing up the menu | + | Dans cette série d' |
+ | |||
+ | Dans la première partie de cette série, nous avons installé l' | ||
+ | |||
+ | **Fleshing up the menu | ||
Let us now create a bespoke menu and make it responsive. To do so, we will overwrite two separate procedures of the standard TApplication object. The first is procedure InitMenuBar which, as its name suggests, populates the menu bar at the top of the screen. The other is the procedure that handles window events, in which we will be defining how our application needs to respond to button presses and suchlike. So our application object derives from the standard TApplication, | Let us now create a bespoke menu and make it responsive. To do so, we will overwrite two separate procedures of the standard TApplication object. The first is procedure InitMenuBar which, as its name suggests, populates the menu bar at the top of the screen. The other is the procedure that handles window events, in which we will be defining how our application needs to respond to button presses and suchlike. So our application object derives from the standard TApplication, | ||
Ligne 9: | Ligne 13: | ||
We will be putting in a very basic menu bar with two submenus: a “File” menu with some standard options, and a “Help menu” with an option to open up the traditional “About” dialog (see box below). | We will be putting in a very basic menu bar with two submenus: a “File” menu with some standard options, and a “Help menu” with an option to open up the traditional “About” dialog (see box below). | ||
- | As readers accustomed to Turbo Pascal will have noticed, this is exactly the same syntax. In fact, I would not be surprised to learn that one of my projects from back then would just compile under Free Pascal. That is, if I manage to dig out the 3½” diskettes and a disk drive that still works. Just to refresh memories, let us note that “~” is used to indicate key accelerators, | + | As readers accustomed to Turbo Pascal will have noticed, this is exactly the same syntax. In fact, I would not be surprised to learn that one of my projects from back then would just compile under Free Pascal. That is, if I manage to dig out the 3½” diskettes and a disk drive that still works. Just to refresh memories, let us note that “~” is used to indicate key accelerators, |
- | Responding to events | + | Étoffer le menu |
+ | |||
+ | Créons un menu sur mesure et rendons-le interactif. Pour ce faire, nous écraserons deux procédures différentes de l' | ||
+ | |||
+ | Nous insérerons une barre de menu basique avec deux sous-menus : un menu « File » (Fichier) avec quelques options standards et un menu « Help » (Aide) avec une option qui ouvrira la traditionnelle boîte de dialogue « About » (À propos) (voir le code ci-dessous). | ||
+ | |||
+ | Comme les lecteurs accoutumés à Turbo Pascal l' | ||
+ | |||
+ | **Responding to events | ||
The menu prepared above will actually respond to some buttons, but not to others. The difference is that TApplication’s default HandleEvent method knows what to do when the cmQuit command is issued (it simply quits). But it has not been programmed to respond to other events, such as the cmHelp command we put into the Help > About menu item. | The menu prepared above will actually respond to some buttons, but not to others. The difference is that TApplication’s default HandleEvent method knows what to do when the cmQuit command is issued (it simply quits). But it has not been programmed to respond to other events, such as the cmHelp command we put into the Help > About menu item. | ||
Ligne 19: | Ligne 31: | ||
It is especially important to include the original HandleEvent with the “inherited” command, since it handles the cmQuit command and we still want that to work. | It is especially important to include the original HandleEvent with the “inherited” command, since it handles the cmQuit command and we still want that to work. | ||
- | To respond to the cmHelp command, we are using a simple if structure to set up a MessageBox. This is a fast way of creating a message dialog box, that can be of several different types (Information, | + | To respond to the cmHelp command, we are using a simple if structure to set up a MessageBox. This is a fast way of creating a message dialog box, that can be of several different types (Information, |
- | Setting up a file input box | + | Répondre aux événements |
+ | |||
+ | Le menu préparé au-dessus répondra bel et bien à certains boutons, mais pas à d' | ||
+ | |||
+ | C'est pourquoi nous remplacerons la méthode HandleEvent existante par la nôtre. Par exemple : | ||
+ | |||
+ | Il est particulièrement important d' | ||
+ | |||
+ | Pour répondre à la commande cmHelp, nous utilisons une simple procédure if pour paramétrer une MessageBox. C'est une façon rapide de créer une boîte de dialogue de message, qui peut être de différents types (Information, | ||
+ | |||
+ | **Setting up a file input box | ||
There are also other, predefined, dialog types available. To take a classic example, in our programs we sometimes need to prompt the user to enter a file through the typical File Open dialog. Free Vision does things in the very same way as Turbo Vision. We will modify our HandleEvent to respond to cmOpen. To do so, we will need several variables: | There are also other, predefined, dialog types available. To take a classic example, in our programs we sometimes need to prompt the user to enter a file through the typical File Open dialog. Free Vision does things in the very same way as Turbo Vision. We will modify our HandleEvent to respond to cmOpen. To do so, we will need several variables: | ||
Ligne 30: | Ligne 52: | ||
pOpen : PFileDialog; | pOpen : PFileDialog; | ||
- | FileName is a string to save the user-inputted filename, result will contain the command code of the button chosen (cmOpen or cmCancel), while pOpen is a pointer to the new dialog to be created. Now, within HandleEvent, | + | FileName is a string to save the user-inputted filename, result will contain the command code of the button chosen (cmOpen or cmCancel), while pOpen is a pointer to the new dialog to be created. Now, within HandleEvent, |
- | We have created a new FileDialog object, specifying that we wish to filter files with the ’*.txt’ pattern. When executed, the command chosen by the user is stored in variable result, and can then be examined to control subsequent actions. | + | Paramétrer une boîte de dialogue de saisie de fichier |
+ | |||
+ | Il y a aussi d' | ||
+ | |||
+ | var | ||
+ | FileName: String; | ||
+ | result : integer; | ||
+ | pOpen : PFileDialog; | ||
+ | |||
+ | FileName est une chaîne de caractères pour sauvegarder le nom de fichier saisi par l' | ||
+ | |||
+ | **We have created a new FileDialog object, specifying that we wish to filter files with the ’*.txt’ pattern. When executed, the command chosen by the user is stored in variable result, and can then be examined to control subsequent actions. | ||
The dialog produced has nothing special to it as it is standard in Turbo and Free Vision. It just works and is very responsive. | The dialog produced has nothing special to it as it is standard in Turbo and Free Vision. It just works and is very responsive. | ||
- | However, there are a couple of points to be noted since the last time I stared at one of these, back in the days of MS-DOS. The first is that it seems to handle well a POSIX file system, with the “/” file separator instead of MS-DOS’s idiosyncratic “C:” and “\”. The user can easily navigate through a standard Ubuntu home directory. On the other hand, we can also see that Unicode characters in filenames that do not appear in the common ASCII codepage (codes up to 127) have been altered, specifically the accents in “Música” and “Públic”. This may be a minor problem for some, or major for others if the intended end user’s environment is mostly in a non-latin script. | + | However, there are a couple of points to be noted since the last time I stared at one of these, back in the days of MS-DOS. The first is that it seems to handle well a POSIX file system, with the “/” file separator instead of MS-DOS’s idiosyncratic “C:” and “\”. The user can easily navigate through a standard Ubuntu home directory. On the other hand, we can also see that Unicode characters in filenames that do not appear in the common ASCII codepage (codes up to 127) have been altered, specifically the accents in “Música” and “Públic”. This may be a minor problem for some, or major for others if the intended end user’s environment is mostly in a non-latin script. |
- | By this point, we have been using several of Free Vision’s library units, which must be included at the beginning of our program file: | + | |
+ | Nous avons créé un objet FileDialog, en spécifiant que nous souhaitons filtrer les fichiers avec le motif « *.txt ». À l' | ||
+ | |||
+ | La boîte de dialogue obtenue n'a rien de spécial car elle est standard dans Turbo et Free Vision. Elle fonctionne tout simplement et est très réactive. | ||
+ | |||
+ | Cependant, depuis la dernière fois que j'en ai contemplé une, du temps de MS-DOS, il y a deux points à noter. Le premier est qu' | ||
+ | |||
+ | **By this point, we have been using several of Free Vision’s library units, which must be included at the beginning of our program file: | ||
+ | |||
+ | uses App, Objects, Menus, Drivers, Views, Dialogs, MsgBox, StdDlg; | ||
+ | |||
+ | The complete code for this example is available at http:// | ||
+ | |||
+ | À ce stade, nous avons utilisé plusieurs unités de la bibliothèque de Free Vision, qui doivent être incluses au début de notre fichier de programme | ||
uses App, Objects, Menus, Drivers, Views, Dialogs, MsgBox, StdDlg; | uses App, Objects, Menus, Drivers, Views, Dialogs, MsgBox, StdDlg; | ||
- | The complete | + | Le code complet de cet exemple est sur http:// |
issue112/tutoriel2.1472472320.txt.gz · Dernière modification : 2016/08/29 14:05 de auntiee