1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| unit Form1_;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ImgList, ToolWin, ExtCtrls, CheckLst, Menus,
ActiveX, Buttons, VBto_Converter;
type
TForm1 = class(TForm)
iblSaisie: TLabel;
TxtSaisie: TEdit;
cmdCalculer: TButton;
mMainMenu1: TMainMenu;
frmexercice03: TMenuItem;
procedure cmdCalculerClick(Sender: TObject);
procedure cmdQuitter_Click();
procedure TxtSaisieKeyPress(Sender: TObject; var Key: char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//===============================================
==========
procedure TForm1.cmdCalculerClick(Sender: TObject);
var
n, Somme: Double;
begin
//{$DEFINE def_cmdCalculer_Click}
{$IF Defined(def_cmdCalculer_Click)}
n := Val(TxtSaisie.Text);
Somme := n*(n+1)/2;
TxtAffichage.Text := 'La somme est '+FloatToStr(Somme);
{$IFEND} // def_cmdCalculer_Click
end;
procedure TForm1.cmdQuitter_Click();
begin
//{$DEFINE def_cmdQuitter_Click}
{$IF Defined(def_cmdQuitter_Click)}
Application.Terminate();
{$IFEND} // def_cmdQuitter_Click
end;
procedure TForm1.TxtSaisieKeyPress(Sender: TObject; var Key: char);
begin
//{$DEFINE def_TxtSaisie_KeyPress}
{$IF Defined(def_TxtSaisie_KeyPress)}
// Autorise seulement la saisie de chiffres
if KeyAscii<48 or KeyAscii>57 then begin
KeyAscii := 0;
Beep();
end;
{$IFEND} // def_TxtSaisie_KeyPress
end;
end. |
Partager