IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Ada Discussion :

Constraint error..s-valuti.adb..explicit raise ?


Sujet :

Ada

  1. #1
    Membre du Club Avatar de Poseidon62
    Inscrit en
    Mars 2004
    Messages
    102
    Détails du profil
    Informations personnelles :
    Âge : 58

    Informations forums :
    Inscription : Mars 2004
    Messages : 102
    Points : 67
    Points
    67
    Par défaut Constraint error..s-valuti.adb..explicit raise ?
    Bonjour,

    Je teste le code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    --***************************************************************
    -- Nom du programme : Calculatrice
    -- Type             : Interface
    -- Sujet            : Calculatrice construite à partir de GTKADA
    --
    -- Auteur           : Pascal RICHARD
    -- Version          : 1.0
    -- Création         : 08/03/2007
    -- Dernière modif.  : 10/03/2007
    --
    -- Outils           : AIDE - GPS - MSys
    -- Remarques        : Environnement Windows XP SP2
    --****************************************************************
    
    with Glib;			use Glib;
    with Gtk.Main;			use Gtk.Main;
    with Gtk.Window;		use Gtk.Window;
    with Gtk.Frame;			use Gtk.Frame;
    with Gtk.GEntry;		use Gtk.GEntry;
    with Gtk.Enums;			use Gtk.Enums;
    with Gtk.Button;		use Gtk.Button;
    with Gtk.Check_Button;		use Gtk.Check_Button;
    with Gtk.Table;			use Gtk.Table;
    with Gtk.Handlers;		use Gtk.Handlers;
    with gtk.widget;		use gtk.widget;
    with gtk.editable;		use gtk.editable;
    with p_calculs;			use p_calculs;
    --with p_calc_outils;		use p_calc_outils;
    --with p_calc_drawing_screen;	use p_calc_drawing_screen;
    with ada.strings.unbounded;	use ada.strings.unbounded;
    with ada.text_io;		use ada.text_io;
    with ada.integer_text_io;	use ada.integer_text_io;
    
    procedure cessai is
    
       Table                                            : gtk_table;
       Fenetre                                          : gtk_window;
       Ecran, Affich_result				    : Gtk_GEntry;
       Frame_affich, Frame_ope, Frame_nomb 		    : gtk_frame;
       btn_plus					    : Gtk_Button;
       btn_clear, btn_exe				    : Gtk_Button;
       bouton0, bouton1				    : gtk_button;
    
       pos : Gint := -1;
       a : string := "";
    
       --bouton: array(0 .. 1) of Gtk_Button;
       G : constant array(0 .. 1) of Guint := (17, 14);
       D : constant array(0 .. 1) of Guint := (20, 17);
       H : constant array(0 .. 1) of Guint := (17, 14);
       B : constant array(0 .. 1) of Guint := (19, 16);
    
    
       ---------------------------------------
       -- package fonctions (spécification) --
       ---------------------------------------
       package Fonctions is
          function Explode (Ch : Unbounded_String ) return Integer;
          function Contrainte_Chaine (Ch : Unbounded_String ) return String;
          function Cpt_Elem_Drt (U_Ch : Unbounded_String) return Integer;
          function Cpt_Elem_Gch (U_Ch : Unbounded_String) return Integer;
          function Chaine_Gauche (Ch : Unbounded_String) return String;
          function Chaine_Droite (Ch : Unbounded_String) return String;
          function Add (Gauche, Droite : Integer) return Integer;
       end Fonctions;
    
    
    
       -------------------------------
       -- package fonctions (corps) --
       -------------------------------
       package body Fonctions is
    
          function Explode (Ch : Unbounded_String ) return Integer is
             Long : Integer;
          begin
             Long := Ada.Strings.Unbounded.Length(Ch);
             return Long;
          end Explode;
    
          function Contrainte_Chaine (Ch : Unbounded_String ) return String is
             Long       : Integer            := Explode (Ch);
             New_Chaine : String (1 .. Long);
          begin
             New_Chaine := Ada.Strings.Unbounded.To_String(Ch);
             return New_Chaine;
          end Contrainte_Chaine;
    
       function Cpt_elem_drt (u_ch : unbounded_string) return Integer is
          Lchaine : String := Contrainte_Chaine(U_Ch);
          long_chaine : integer;
          Count, Count_gch, count_drt : Integer;
       begin
          count := 0;
          Count_Gch := 0;
          Count_Drt := 0;
          long_chaine := explode(u_ch);
          for I in 1 .. Long_chaine loop
             if lchaine(I) /= '+' then
                Count := Count + 1;
             elsif lchaine(I) = '+' then
                Count_Drt := long_chaine - Count - 1;
             end if;
          end loop;
          Count_Gch := Long_chaine - Count_Drt - 1;
          return Count_Drt;
       end Cpt_elem_drt;
    
       function Cpt_Elem_Gch (u_ch : unbounded_string) return Integer is
          gauche : integer;
       begin
          Gauche := Explode(u_Ch) - Cpt_Elem_drt(u_Ch) - 1;
          return gauche;
       end Cpt_Elem_Gch;
    
          function Chaine_gauche (Ch : unbounded_String ) return String is
             Depart : Positive := 1;
             Fin : Natural := Cpt_Elem_Gch(Ch);
          begin
             return ada.strings.unbounded.slice(ch, depart, fin);
          end Chaine_gauche;
    
          function Chaine_Droite (Ch : Unbounded_String ) return String is
             dep_drt : positive := cpt_elem_gch(ch) + 2;
             Fin : Natural := explode(Ch);
          begin
             return ada.strings.unbounded.slice(ch, dep_drt, fin);
          end Chaine_Droite;
    
          function Add (Gauche, Droite : Integer) return Integer is
          begin
             return Gauche + Droite;
          end Add;
    
       end Fonctions;
    
       --use fonctions;
    
       ------------------------------------------
       -- package aff_chiffres (spécification) --
       ------------------------------------------
    
       package aff_chiffres is
    
          procedure affich0 (emet : access gtk_widget_record'class);
          procedure affich1 (emet : access gtk_widget_record'class);
    
       end aff_chiffres;
    
    
    
       ----------------------------------
       -- package aff_chiffres (corps) --
       ----------------------------------
    
       package body aff_chiffres is
    
          procedure affich0 (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "0", pos); -- fonction issue de Gtk.Editable
          end affich0;
    
          procedure affich1 (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "1", pos);
          end affich1;
    
       end aff_chiffres;
    
    
    
       ----------------------------------------
       -- package aff_outils (spécification) --
       ----------------------------------------
    
       package aff_outils is
    
          -- Conversions de types --
          function Int_Str (X : Integer) return string;
          function int_ustr (X : integer) return unbounded_string;
          function ustr_int (X : unbounded_string) return integer;
          function ustr_str (X : unbounded_string) return string;
    
          -- opérations élémentaires --
          procedure Add (X, Y : integer);
          procedure Sou (X, Y : Integer);
          procedure Mul (X, Y : Integer);
          procedure Div (X, Y : Integer);
    
          -- Actions --
          procedure calculer (emet : access gtk_widget_record'class);
          procedure affich_plus (emet : access gtk_widget_record'class);
          procedure effacer (emet : access gtk_widget_record'class);
          procedure aff_resultat (emet : access gtk_widget_record'class);
    
       end aff_outils;
    
    
    
       ----------------------------------------
       -- package aff_outils (spécification) --
       ----------------------------------------
    
       package p_pile is
    
          -- Empiler / Dépiler --
          procedure empiler (X : integer);
          function depiler return integer;
          procedure empiler_ustr (X : unbounded_string);
          function depiler_ustr return unbounded_string;
    
       end p_pile;
    
    
    
       --------------------------------
       -- package aff_outils (corps) --
       --------------------------------
    
       package body aff_outils is
    
          use p_pile;
    
          -- Conversions de types --
          function Int_Str (X : Integer) return string is
          begin
             return integer'image(X);
          end Int_Str;
    
          function int_ustr (X : integer) return unbounded_string is
          begin
             return ada.strings.unbounded.to_unbounded_string(integer'image(X));
          end int_ustr;
    
          function ustr_int (X : unbounded_string) return integer is
          begin
             return integer'value(ada.strings.unbounded.to_string(x));
          end ustr_int;
    
          function ustr_str (X : unbounded_string) return string is
          begin
             return ada.strings.unbounded.to_string(X);
          end ustr_str;
    
    
          -- Actions --
          procedure affich_plus (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "+", pos);
          end affich_plus;
    
          procedure effacer (emet : access gtk_widget_record'class) is
          begin
             delete_text(Ecran, 0, pos);
          end effacer;
    
    
          -- Opérations élémentaires --
          procedure Add (X, Y : integer) is
             resultat : integer;
          begin
             resultat := X + Y;
             empiler(resultat);
          end Add;
    
          procedure Sou (X, Y : integer) is
             resultat : integer;
          begin
             resultat := X - Y;
             empiler(resultat);
          end Sou;
    
          procedure Mul (X, Y : Integer) is
             resultat : integer;
          begin
             resultat := X * Y;
             empiler(resultat);
          end Mul;
    
          procedure Div (X, Y : Integer) is
             resultat : integer;
          begin
             resultat := X / Y;
             empiler(resultat);
          end Div;
    
          procedure calculer (emet : access gtk_widget_record'class) is
    
             use p_pile;
    
             V_E1_int : Integer;
             E1, N : unbounded_string;
             e1_str : string := "";
        
    
          begin
    
             E1 := ada.strings.unbounded.to_unbounded_string(integer'value(get_chars (Ecran, 0, -1)));
             v_e1_int := fonctions.explode(E1);
             E1_str := fonctions.contrainte_chaine(E1);     
             insert_text(affich_result, E1_str, pos);
    
          end calculer;
    
          procedure aff_resultat (emet : access gtk_widget_record'class) is
    
             b : unbounded_string;
             c : string := "";
    
          begin
    
             b := depiler_ustr;
             c := ustr_str(b);
             insert_text (Affich_result, c, pos);
    
          end aff_resultat;
    
       end aff_outils;
    
    
    
       ----------------------------
       -- package p_pile (corps) --
       ----------------------------
    
       package body p_pile is
    
          max : constant := 3;
          pile : array (1 .. max) of integer;
          pile_ustr : array (1 .. max) of unbounded_string;
          sommet, sommet_ustr : integer range 0 .. max;
    
    
          -- Empiler / Dépiler --
          procedure empiler (x : integer) is
          begin
             sommet := sommet + 1;
             pile (sommet) := x;
          end empiler;
    
          function depiler return integer is
          begin
             sommet := sommet - 1;
             return pile (sommet + 1);
          end depiler;
    
          procedure empiler_ustr (x : unbounded_string) is
          begin
             sommet_ustr := sommet_ustr + 1;
             pile_ustr (sommet_ustr) := X;
          end empiler_ustr;
    
          function depiler_ustr return unbounded_string is
          begin
             sommet_ustr := sommet_ustr - 1;
             return pile_ustr (sommet_ustr + 1);
          end depiler_ustr;
    
       begin
          sommet := 0;
          sommet_ustr := 0;
       end p_pile;
    
       package traitement is new callback (gtk_widget_record);
       package traitement_tools is new callback (gtk_widget_record);
    --     type String_Ptr is access all String;
    --
    --     procedure Affich (Emet : access Gtk_Widget_Record'Class;
    --                     Data : String_Ptr) is
    --     begin
    --        Insert_Text(Ecran, Data.all , Pos);
    --     end affich;
    --
    --     package Traitement is new Gtk.Handlers.User_Callback
    --       (Widget_Type => Gtk_Widget_Record,
    --        User_Type   => String_Ptr);
    
    
    
       --use aff_outils;
    
    begin
    
    init;
    
       -- Création de la fenetre
       gtk_new(fenetre, window_toplevel);
       set_size_request(fenetre, 400, 300);
       set_position(fenetre, win_pos_center);
    
       gtk_new(Table, 21, 25, true);
       add(fenetre, Table);
    
    
    
       -- Création d'un Frame "Affichage", suivi
       -- de la Création de l'écran d'affichage
       gtk_new(Frame_affich, "Affichage");
       attach_defaults(Table, Frame_affich, 1, 24, 1, 6);
    
       gtk_new(Ecran);
       attach_defaults(Table, Ecran, 2, 9, 2, 3);
       set_has_frame (Ecran, false);
       set_editable (Ecran, False);
    
    --     gtk_new(Ecran2);
    --     attach_defaults(Table, Ecran2, 9, 12, 2, 3);
    --     set_has_frame (Ecran2, false);
    --     set_editable (Ecran2, False);
    --
    --     gtk_new(Ecran3);
    --     attach_defaults(Table, Ecran3, 12, 19, 2, 3);
    --     set_has_frame (Ecran3, false);
    --     set_editable (Ecran3, False);
    
       gtk_new(Affich_result);
       attach_defaults(Table, Affich_result, 2, 19, 4, 5);
       set_editable (Affich_result, False);
    
       gtk_new(btn_exe, "EXE");
       attach_defaults(Table, btn_exe, 20, 23, 2, 5);
       traitement_tools.connect (btn_exe, "clicked", traitement_tools.to_marshaller(aff_outils.calculer'access));
    
    
       -- Création des boutons du frame "Opérations" - opérations usuelles
       -- suivi de la création des boutons relatifs à ce frame
       gtk_new(Frame_ope, "Operations");
       attach_defaults(Table, frame_ope, 1, 12, 13, 20);
    
       gtk_new(btn_plus, "+");
       attach_defaults(Table, btn_plus, 3, 5, 15, 17);
       traitement_tools.connect (btn_plus, "clicked", traitement_tools.to_marshaller(aff_outils.affich_plus'access));
    
    
    
       -- Création du Frame "Nombres" suivi de la
       -- création des boutons "virgule" et "puissance de 10", suivi de
       -- la création d'une boucle pour générer les x boutons chiffres
       gtk_new(Frame_nomb, "Chiffres");
       attach_defaults(Table, Frame_nomb, 13, 24, 7, 20);
    
       gtk_new(btn_clear, "C");
       attach_defaults(Table, btn_clear, 20, 23, 17, 19);
       traitement_tools.connect (btn_clear, "clicked", traitement_tools.to_marshaller(aff_outils.effacer'access));
    
    
       gtk_new(bouton0, "0");
       attach_defaults(Table, bouton0, g(0), d(0), h(0), b(0));
       traitement.connect (bouton0, "clicked", traitement.to_marshaller(aff_chiffres.affich0'access));
    
       gtk_new(bouton1, "1");
       attach_defaults(Table, bouton1, g(1), d(1), h(1), b(1));
       traitement.connect (bouton1, "clicked", traitement.to_marshaller(aff_chiffres.affich1'access));
    
    
    --     for J in Bouton'Range loop
    --        Gtk_New(Bouton(J), Integer'Image(J));
    --        Traitement.Connect(Bouton(J),
    --                           "clicked",
    --                           Traitement.To_Marshaller(Affich'Access),
    --                           new String'(get_label(bouton(J)))); --Integer'Image(J)));
    --     end loop;
    --
    --
    --     for J in bouton'range loop
    --        attach_defaults(Table, bouton(J), G(J), D(J), H(J), B(J));
    --     end loop;
    
    show_all(fenetre);
    main;
    
    end cessai;
    et j'obtiens le message d'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    raised CONSTRAINT_ERROR : s-valuti.adb:236 explicit raise
    Je ne comprends pas bien d'où vient le problème

    Quelqu'un a t-il une idée ?

    Merci

  2. #2
    Membre habitué
    Inscrit en
    Décembre 2004
    Messages
    119
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 119
    Points : 156
    Points
    156
    Par défaut
    "explicit raise" : car tu es tombe sur l'instruction "raise Constraint_Error".
    Vu le package, je dirai qu'un de tes 'Value se passe mal, e.g. la chaine que tu passes est malformee.

    Pour avoir le backtrace de ton exception, fournis l'option -E a gnatbind (si tu utilises bien gnat).
    Tu pourras remonter a l'instruction ayant conduit a l'explosion avec addr2line ou le gpc-mode d'emacs.

    Ou alors pour du plus "normal", tu debug sous ton IDE (si c'est GPS, c'est plutot simple).

    A+

    Juan

  3. #3
    Membre du Club Avatar de Poseidon62
    Inscrit en
    Mars 2004
    Messages
    102
    Détails du profil
    Informations personnelles :
    Âge : 58

    Informations forums :
    Inscription : Mars 2004
    Messages : 102
    Points : 67
    Points
    67
    Par défaut
    Merci pour la réponse.

    Mais pourrais-tu faire un petit topo.
    En fait, j'écris le programme dans GPS, mais je lance les applis depuis la console MSys.

    Quand je veux lancer l'appli depuis GPS, j'ai une interaction avec mon antivirus, donc je ne me sers pas de GPS.

    La console MSys fonctionne est une console unix, mais là je ne connais pas toutes les manips.

    Merci

  4. #4
    Membre habitué
    Inscrit en
    Décembre 2004
    Messages
    119
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 119
    Points : 156
    Points
    156
    Par défaut
    Solution simple, tu mets en veille ton anti-virus le temps de debug.
    Sinon, vérifie si tu as accès à addr2line dans ta console.
    Si c'est vraiment du unix-like, alors, tu peux vérifier en faisant:
    Si c'est le cas, alors, on passe à la génération de ton executable avec les bonnes options:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    > gnatmake -g cessai -bargs -E
    Ensuite, tu l'executes et tu le fais exploser.
    Une fois qu'il explose, tu devrais voir une sortie du genre:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    Execution terminated by unhandled exception
    Exception name: CONSTRAINT_ERROR
    Message: s-valuti.adb:277 explicit raise
    Call stack traceback locations:
    0x165b0 0xf43c 0x245c 0x23c0 0x1d3c 0x1a40 0xfffffc
    En utilisant addr2line comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    > addr2line -e cessai -f 0x165b0 0xf43c 0x245c 0x23c0 0x1d3c 0x1a40 0xfffffc
    Tu obtiens le backtrace en clair (mon programme exemple s'appelait titi):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    0x165b0 in ada__exceptions__code_address_for_zzz at /macon.a/gnatmail/release-gpl/build-macon/obj/gcc/ada/rts/a-except.adb:1352
    0xf43c in ada_titi at /Users/juan-carlosmiranda/Ada/temp/titi.adb:9
    0x245c in ada_titi at /Users/juan-carlosmiranda/Ada/temp/titi.adb:7
    0x23c0 in main at /Users/juan-carlosmiranda/Ada/temp/b~titi.adb:176
    0x1d3c in ?? at titi:0
    0x1a40 in ?? at titi:0
    0xfffffc in ?? at ??:0
    mon programme a, en l'occurrence, crashe à la ligne 7:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    B := Integer'Value(A);
    car A valait "123F4".

    En esperant que ca t'aide.

    Si tu n'as pas addr2line, tu peux essayer d'utiliser gdb depuis ta console sinon.

    En esperant que tu trouves ton bonheur.
    Enfin, le plus simple, c'est quand même de mettre en veille l'anti-virus. ^

  5. #5
    Membre du Club Avatar de Poseidon62
    Inscrit en
    Mars 2004
    Messages
    102
    Détails du profil
    Informations personnelles :
    Âge : 58

    Informations forums :
    Inscription : Mars 2004
    Messages : 102
    Points : 67
    Points
    67
    Par défaut
    Je viens de "debugger" le programme, et apparemment, il trouve une erreur sur l'une des fonctions empiler / depiler, mais je ne vois pas pourquoi, dans la mesure où tout ce qui a été empiler est bien dépiler.

    Les images sont jointes

    Ce message d'erreur m'a été renvoyé après avoir saisi les deux opérandes et le signe, et plus particulièrement après avoir cliqué sur "EXE".

    Je joins le code à tout hasard :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    --***************************************************************
    -- Nom du programme : Calculatrice
    -- Type             : Interface
    -- Sujet            : Calculatrice construite à partir de GTKADA
    --
    -- Auteur           : Pascal RICHARD
    -- Version          : 1.0
    -- Création         : 08/03/2007
    -- Dernière modif.  : 10/03/2007
    --
    -- Outils           : AIDE - GPS - MSys
    -- Remarques        : Environnement Windows XP SP2
    --****************************************************************
    
    with Glib;			use Glib;
    with Gtk.Main;			use Gtk.Main;
    with Gtk.Window;		use Gtk.Window;
    with Gtk.Frame;			use Gtk.Frame;
    with Gtk.GEntry;		use Gtk.GEntry;
    with Gtk.Enums;			use Gtk.Enums;
    with Gtk.Button;		use Gtk.Button;
    with Gtk.Check_Button;		use Gtk.Check_Button;
    with Gtk.Table;			use Gtk.Table;
    with Gtk.Handlers;		use Gtk.Handlers;
    with gtk.widget;		use gtk.widget;
    with gtk.editable;		use gtk.editable;
    with p_calculs;			use p_calculs;
    --with p_calc_outils;		use p_calc_outils;
    --with p_calc_drawing_screen;	use p_calc_drawing_screen;
    with ada.strings.unbounded;	use ada.strings.unbounded;
    with ada.text_io;		use ada.text_io;
    with ada.integer_text_io;	use ada.integer_text_io;
    
    procedure cessai is
    
       Table                                            : gtk_table;
       Fenetre                                          : gtk_window;
       Ecran, Affich_result				    : Gtk_GEntry;
       Frame_affich, Frame_ope, Frame_nomb 		    : gtk_frame;
       btn_plus					    : Gtk_Button;
       btn_clear, btn_exe				    : Gtk_Button;
       bouton0, bouton1				    : gtk_button;
    
       pos : Gint := -1;
       a : string := "";
    
       --bouton: array(0 .. 1) of Gtk_Button;
       G : constant array(0 .. 1) of Guint := (17, 14);
       D : constant array(0 .. 1) of Guint := (20, 17);
       H : constant array(0 .. 1) of Guint := (17, 14);
       B : constant array(0 .. 1) of Guint := (19, 16);
    
    
       ---------------------------------------
       -- package fonctions (spécification) --
       ---------------------------------------
       package Fonctions is
          function Explode (Ch : Unbounded_String ) return Integer;
          function Contrainte_Chaine (Ch : Unbounded_String ) return String;
          function Cpt_Elem_Drt (U_Ch : Unbounded_String) return Integer;
          function Cpt_Elem_Gch (U_Ch : Unbounded_String) return Integer;
          function Chaine_Gauche (Ch : Unbounded_String) return String;
          function Chaine_Droite (Ch : Unbounded_String) return String;
          function Add (Gauche, Droite : Integer) return Integer;
       end Fonctions;
    
    
    
       -------------------------------
       -- package fonctions (corps) --
       -------------------------------
       package body Fonctions is
    
          function Explode (Ch : Unbounded_String ) return Integer is
             Long : Integer;
          begin
             Long := Ada.Strings.Unbounded.Length(Ch);
             return Long;
          end Explode;
    
          function Contrainte_Chaine (Ch : Unbounded_String ) return String is
             Long       : Integer            := Explode (Ch);
             New_Chaine : String (1 .. Long);
          begin
             New_Chaine := Ada.Strings.Unbounded.To_String(Ch);
             return New_Chaine;
          end Contrainte_Chaine;
    
       function Cpt_elem_drt (u_ch : unbounded_string) return Integer is
          Lchaine : String := Contrainte_Chaine(U_Ch);
          long_chaine : integer;
          Count, Count_gch, count_drt : Integer;
       begin
          count := 0;
          Count_Gch := 0;
          Count_Drt := 0;
          long_chaine := explode(u_ch);
          for I in 1 .. Long_chaine loop
             if lchaine(I) /= '+' then
                Count := Count + 1;
             elsif lchaine(I) = '+' then
                Count_Drt := long_chaine - Count - 1;
             end if;
          end loop;
          Count_Gch := Long_chaine - Count_Drt - 1;
          return Count_Drt;
       end Cpt_elem_drt;
    
       function Cpt_Elem_Gch (u_ch : unbounded_string) return Integer is
          gauche : integer;
       begin
          Gauche := Explode(u_Ch) - Cpt_Elem_drt(u_Ch) - 1;
          return gauche;
       end Cpt_Elem_Gch;
    
          function Chaine_gauche (Ch : unbounded_String ) return String is
             Depart : Positive := 1;
             Fin : Natural := Cpt_Elem_Gch(Ch);
          begin
             return ada.strings.unbounded.slice(ch, depart, fin);
          end Chaine_gauche;
    
          function Chaine_Droite (Ch : Unbounded_String ) return String is
             dep_drt : positive := cpt_elem_gch(ch) + 2;
             Fin : Natural := explode(Ch);
          begin
             return ada.strings.unbounded.slice(ch, dep_drt, fin);
          end Chaine_Droite;
    
          function Add (Gauche, Droite : Integer) return Integer is
          begin
             return Gauche + Droite;
          end Add;
    
       end Fonctions;
    
       --use fonctions;
    
       ------------------------------------------
       -- package aff_chiffres (spécification) --
       ------------------------------------------
    
       package aff_chiffres is
    
          procedure affich0 (emet : access gtk_widget_record'class);
          procedure affich1 (emet : access gtk_widget_record'class);
    
       end aff_chiffres;
    
    
    
       ----------------------------------
       -- package aff_chiffres (corps) --
       ----------------------------------
    
       package body aff_chiffres is
    
          procedure affich0 (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "0", pos); -- fonction issue de Gtk.Editable
          end affich0;
    
          procedure affich1 (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "1", pos);
          end affich1;
    
       end aff_chiffres;
    
    
    
       ----------------------------------------
       -- package aff_outils (spécification) --
       ----------------------------------------
    
       package aff_outils is
    
          -- Conversions de types --
          function Int_Str (X : Integer) return string;
          function int_ustr (X : integer) return unbounded_string;
          function ustr_int (X : unbounded_string) return integer;
          function ustr_str (X : unbounded_string) return string;
    
          -- opérations élémentaires --
          procedure Add (X, Y : integer);
          procedure Sou (X, Y : Integer);
          procedure Mul (X, Y : Integer);
          procedure Div (X, Y : Integer);
    
          -- Actions --
          procedure stockage_ustr;
          --procedure calculer (emet : access gtk_widget_record'class);
          procedure affich_plus (emet : access gtk_widget_record'class);
          procedure effacer (emet : access gtk_widget_record'class);
          procedure afficher_resultat (emet : access gtk_widget_record'class);
    
       end aff_outils;
    
    
    
       ------------------------------------
       -- package p_pile (spécification) --
       ------------------------------------
    
       package p_pile is
    
          -- Empiler / Dépiler --
          procedure empiler (X : integer);
          function depiler return integer;
          procedure empiler_sig (x : character);
          function depiler_sig return character;
          procedure empiler_ustr (X : unbounded_string);
          function depiler_ustr return unbounded_string;
    
       end p_pile;
    
    
       ----------------------------
       -- package p_pile (corps) --
       ----------------------------
    
       package body p_pile is
    
             max : constant := 2;
             max_sig : constant := 1;
             pile : array (1 .. max) of integer;
             pile_ustr : array (1 .. max) of unbounded_string;
             pile_sig : array (1 .. max) of character;
             sommet, sommet_ustr : integer range 0 .. max;
             sommet_sig : integer range 0 .. max_sig;
    
          -- Empiler / Dépiler --
          procedure empiler (x : integer) is
          begin
             sommet := sommet + 1;
             pile (sommet) := x;
          end empiler;
    
          function depiler return integer is
          begin
             sommet := sommet - 1;
             return pile (sommet + 1);
          end depiler;
    
             procedure empiler_sig (x : character) is
             begin
                sommet_sig := sommet_sig + 1;
                pile_sig (sommet_sig) := x;
             end empiler_sig;
    
             function depiler_sig return character is
             begin
                sommet_sig := sommet_sig - 1;
                return pile_sig (sommet_sig + 1);
             end depiler_sig;
    
          procedure empiler_ustr (x : unbounded_string) is
          begin
             sommet_ustr := sommet_ustr + 1;
             pile_ustr (sommet_ustr) := X;
          end empiler_ustr;
    
          function depiler_ustr return unbounded_string is
          begin
             sommet_ustr := sommet_ustr - 1;
             return pile_ustr (sommet_ustr + 1);
          end depiler_ustr;
    
       begin
          sommet := 0;
          sommet_ustr := 0;
          sommet_sig := 0;
       end p_pile;
    
    
       --------------------------------
       -- package aff_outils (corps) --
       --------------------------------
    
       package body aff_outils is
    
          use p_pile;
    
          -- Conversions de types --
          function Int_Str (X : Integer) return string is
          begin
             return integer'image(X);
          end Int_Str;
    
          function int_ustr (X : integer) return unbounded_string is
          begin
             return ada.strings.unbounded.to_unbounded_string(integer'image(X));
          end int_ustr;
    
          function ustr_int (X : unbounded_string) return integer is
          begin
             return integer'value(ada.strings.unbounded.to_string(x));
          end ustr_int;
    
          function ustr_str (X : unbounded_string) return string is
          begin
             return ada.strings.unbounded.to_string(X);
          end ustr_str;
    
    
          -- Actions --
          procedure affich_plus (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "+", pos);
          end affich_plus;
    
          procedure effacer (emet : access gtk_widget_record'class) is
          begin
             delete_text(Ecran, 0, pos);
          end effacer;
    
    
          -- Opérations élémentaires --
          procedure Add (X, Y : integer) is
             resultat : integer;
          begin
             resultat := X + Y;
             empiler(resultat);
          end Add;
    
          procedure Sou (X, Y : integer) is
             resultat : integer;
          begin
             resultat := X - Y;
             empiler(resultat);
          end Sou;
    
          procedure Mul (X, Y : Integer) is
             resultat : integer;
          begin
             resultat := X * Y;
             empiler(resultat);
          end Mul;
    
          procedure Div (X, Y : Integer) is
             resultat : integer;
          begin
             resultat := X / Y;
             empiler(resultat);
          end Div;
    
          procedure stockage_ustr is
    
            use fonctions;
            use p_pile;
    
             chaine : unbounded_string;
             chaine_de_gauche : unbounded_string;
             chaine_de_droite : unbounded_string;
             valeurI_de_gauche : integer;
             valeurI_de_droite : integer;
             nb_elem_gch : integer;
             signe : character;
    
          begin
    
                nb_elem_gch := cpt_elem_gch(chaine);
                chaine := ada.strings.unbounded.to_unbounded_string(get_chars (Ecran, 0, -1));
    
                -- Empilement des différentes valeurs de la U_chaine
                -- Deux U_chaines (droite  et gauche) dans un empiler_ustr
                -- Un signe de type character dans un empiler_sig
             chaine_de_droite := ada.strings.unbounded.to_unbounded_string(chaine_droite(chaine));
             valeurI_de_droite := integer'value(ada.strings.unbounded.to_string(chaine_de_droite));
             empiler(valeurI_de_droite);
                --empiler_ustr(chaine_de_droite);
             chaine_de_gauche := ada.strings.unbounded.to_unbounded_string(chaine_gauche(chaine));
             valeurI_de_gauche := integer'value(ada.strings.unbounded.to_string(chaine_de_gauche));
             empiler(valeurI_de_gauche);
                --empiler_ustr(chaine_de_gauche);
                signe := ada.strings.unbounded.element(chaine, nb_elem_gch + 1);
                empiler_sig(signe);
    
             --insert_text(affich_result, E1_str, pos);
    
          end stockage_ustr;
    
    
          procedure calculer (i1, i2 : integer) is
    
             nb1 : integer := depiler;
             signe : character;
             nb2 : integer := depiler;
    
          begin
    
             signe := depiler_sig;
    
             case signe is
                when '+' => add(nb1, nb2);
                when '-' => sou(nb1, nb2);
                when '*' => mul(nb1, nb2);
                when '/' => div(nb1, nb2);
                   when others => null;
             end case;
    
          end calculer;
    
          procedure afficher_resultat (emet : access gtk_widget_record'class) is
    
             int : integer := depiler;
             str : string := int_str(int);
    
          begin
    
             insert_text (Affich_result, str, pos);
    
          end afficher_resultat;
    
       end aff_outils;
    
    
    
       package traitement is new callback (gtk_widget_record);
       package traitement_tools is new callback (gtk_widget_record);
    --     type String_Ptr is access all String;
    --
    --     procedure Affich (Emet : access Gtk_Widget_Record'Class;
    --                     Data : String_Ptr) is
    --     begin
    --        Insert_Text(Ecran, Data.all , Pos);
    --     end affich;
    --
    --     package Traitement is new Gtk.Handlers.User_Callback
    --       (Widget_Type => Gtk_Widget_Record,
    --        User_Type   => String_Ptr);
    
    
    
       --use aff_outils;
    
    begin
    
    init;
    
       -- Création de la fenetre
       gtk_new(fenetre, window_toplevel);
       set_size_request(fenetre, 400, 300);
       set_position(fenetre, win_pos_center);
    
       gtk_new(Table, 21, 25, true);
       add(fenetre, Table);
    
    
    
       -- Création d'un Frame "Affichage", suivi
       -- de la Création de l'écran d'affichage
       gtk_new(Frame_affich, "Affichage");
       attach_defaults(Table, Frame_affich, 1, 24, 1, 6);
    
       gtk_new(Ecran);
       attach_defaults(Table, Ecran, 2, 9, 2, 3);
       set_has_frame (Ecran, false);
       set_editable (Ecran, False);
    
    --     gtk_new(Ecran2);
    --     attach_defaults(Table, Ecran2, 9, 12, 2, 3);
    --     set_has_frame (Ecran2, false);
    --     set_editable (Ecran2, False);
    --
    --     gtk_new(Ecran3);
    --     attach_defaults(Table, Ecran3, 12, 19, 2, 3);
    --     set_has_frame (Ecran3, false);
    --     set_editable (Ecran3, False);
    
       gtk_new(Affich_result);
       attach_defaults(Table, Affich_result, 2, 19, 4, 5);
       set_editable (Affich_result, False);
    
       gtk_new(btn_exe, "EXE");
       attach_defaults(Table, btn_exe, 20, 23, 2, 5);
       traitement_tools.connect (btn_exe, "clicked", traitement_tools.to_marshaller(aff_outils.afficher_resultat'access));
    
    
       -- Création des boutons du frame "Opérations" - opérations usuelles
       -- suivi de la création des boutons relatifs à ce frame
       gtk_new(Frame_ope, "Operations");
       attach_defaults(Table, frame_ope, 1, 12, 13, 20);
    
       gtk_new(btn_plus, "+");
       attach_defaults(Table, btn_plus, 3, 5, 15, 17);
       traitement_tools.connect (btn_plus, "clicked", traitement_tools.to_marshaller(aff_outils.affich_plus'access));
    
    
    
       -- Création du Frame "Nombres" suivi de la
       -- création des boutons "virgule" et "puissance de 10", suivi de
       -- la création d'une boucle pour générer les x boutons chiffres
       gtk_new(Frame_nomb, "Chiffres");
       attach_defaults(Table, Frame_nomb, 13, 24, 7, 20);
    
       gtk_new(btn_clear, "C");
       attach_defaults(Table, btn_clear, 20, 23, 17, 19);
       traitement_tools.connect (btn_clear, "clicked", traitement_tools.to_marshaller(aff_outils.effacer'access));
    
    
       gtk_new(bouton0, "0");
       attach_defaults(Table, bouton0, g(0), d(0), h(0), b(0));
       traitement.connect (bouton0, "clicked", traitement.to_marshaller(aff_chiffres.affich0'access));
    
       gtk_new(bouton1, "1");
       attach_defaults(Table, bouton1, g(1), d(1), h(1), b(1));
       traitement.connect (bouton1, "clicked", traitement.to_marshaller(aff_chiffres.affich1'access));
    
    
    --     for J in Bouton'Range loop
    --        Gtk_New(Bouton(J), Integer'Image(J));
    --        Traitement.Connect(Bouton(J),
    --                           "clicked",
    --                           Traitement.To_Marshaller(Affich'Access),
    --                           new String'(get_label(bouton(J)))); --Integer'Image(J)));
    --     end loop;
    --
    --
    --     for J in bouton'range loop
    --        attach_defaults(Table, bouton(J), G(J), D(J), H(J), B(J));
    --     end loop;
    
    show_all(fenetre);
    main;
    
    end cessai;
    Images attachées Images attachées   

  6. #6
    Membre habitué
    Inscrit en
    Décembre 2004
    Messages
    119
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 119
    Points : 156
    Points
    156
    Par défaut
    Ce n'est pas le même problème que le précédent (même si c'est effectivement une Constraint_Error).

    Il ne te reste qu'à analyser les variables au moment du crash (l'état de ta pile, la valeur des variables, ...).

    Bon courage.

  7. #7
    Membre régulier Avatar de poincare
    Homme Profil pro
    Architecte technique
    Inscrit en
    Mai 2007
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Architecte technique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2007
    Messages : 48
    Points : 81
    Points
    81
    Par défaut Retracer l'erreur
    Dans Gnat, il existe le package :

    GNAT.Traceback.Symbolic;

    qui permet de lister les emplacements où l'exception a été levée.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    with GNAT.Traceback.Symbolic;
    with Ada.Exceptions;
     
    procedure Foo is
     
     
    exception
       when E : others =>
          Text_IO.Put_Line
            ("FATAL : " & Ada.Exceptions.Exception_Information (E));
     
          Text_IO.Put_Line
             (GNAT.Traceback.Symbolic.Symbolic_Traceback (E));

  8. #8
    Membre du Club Avatar de Poseidon62
    Inscrit en
    Mars 2004
    Messages
    102
    Détails du profil
    Informations personnelles :
    Âge : 58

    Informations forums :
    Inscription : Mars 2004
    Messages : 102
    Points : 67
    Points
    67
    Par défaut
    Re....

    Voilà, j'ai fait toute une batterie de tests.
    A la suite de ces tests, j'ai décidé de virer les piles.
    Je suis donc passé à une méthode simpliste, mais qui marche en partie !!!

    En fait, le calcul marche pour le plus (cf image ci-jointe), mais dès que je veux faire une soustraction, une multiplication ou une division, il me met l'erreur suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    raised CONSTRAINT_ERROR : s-valuti.adb:236 explicit raise
    Voici le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    --***************************************************************
    -- Nom du programme : Calculatrice
    -- Type             : Interface
    -- Sujet            : Calculatrice construite à partir de GTKADA
    --
    -- Auteur           : Pascal RICHARD
    -- Version          : 5.0
    -- Création         : 08/03/2007
    -- Dernière modif.  : 15/05/2007
    --
    -- Outils           : AIDE - GPS - MSys
    -- Remarques        : Environnement Windows XP SP2
    --****************************************************************
     
    with Glib;			use Glib;
    with Gtk.Main;			use Gtk.Main;
    with Gtk.Window;		use Gtk.Window;
    with Gtk.Frame;			use Gtk.Frame;
    with Gtk.GEntry;		use Gtk.GEntry;
    with Gtk.Enums;			use Gtk.Enums;
    with Gtk.Button;		use Gtk.Button;
    with Gtk.Check_Button;		use Gtk.Check_Button;
    with Gtk.Table;			use Gtk.Table;
    with Gtk.Handlers;		use Gtk.Handlers;
    with gtk.widget;		use gtk.widget;
    with gtk.editable;		use gtk.editable;
    with p_calculs;			use p_calculs;
    with ada.strings.unbounded;	use ada.strings.unbounded;
    with ada.text_io;		use ada.text_io;
    with ada.integer_text_io;	use ada.integer_text_io;
    with p_fonctions;		use p_fonctions;
    with p_pile;			use p_pile;
    with p_operations;		use p_operations;
     
    procedure cessai2 is
     
       Table                                            : gtk_table;
       Fenetre                                          : gtk_window;
       Ecran, Affich_result				    : Gtk_GEntry;
       Frame_affich, Frame_ope, Frame_nomb 		    : gtk_frame;
       btn_plus, btn_moins, btn_mul, btn_div	    : Gtk_Button;
       btn_clear, btn_exe				    : Gtk_Button;
       bouton0, bouton1, bouton2			    : gtk_button;
     
       pos : Gint := -1;
       a : string := "";
       U_result : unbounded_string;
     
       --bouton: array(0 .. 1) of Gtk_Button;
       G : constant array(0 .. 2) of Guint := (17, 14, 17);
       D : constant array(0 .. 2) of Guint := (20, 17, 20);
       H : constant array(0 .. 2) of Guint := (17, 14, 14);
       B : constant array(0 .. 2) of Guint := (19, 16, 16);
     
     
       ------------------------------------------
       -- package aff_chiffres (spécification) --
       ------------------------------------------
     
       package aff_chiffres is
     
          procedure affich0 (emet : access gtk_widget_record'class);
          procedure affich1 (emet : access gtk_widget_record'class);
          procedure affich2 (emet : access gtk_widget_record'class);
     
       end aff_chiffres;
     
     
     
       ----------------------------------
       -- package aff_chiffres (corps) --
       ----------------------------------
     
       package body aff_chiffres is
     
          procedure affich0 (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "0", pos); -- fonction issue de Gtk.Editable
          end affich0;
     
          procedure affich1 (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "1", pos);
          end affich1;
     
          procedure affich2 (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "2", pos);
          end affich2;
     
       end aff_chiffres;
     
     
     
       ----------------------------------------
       -- package aff_outils (spécification) --
       ----------------------------------------
     
       package aff_outils is
     
          -- Actions --
          procedure affich_plus (emet : access gtk_widget_record'class);
          procedure affich_moins (emet : access gtk_widget_record'class);
          procedure affich_mul (emet : access gtk_widget_record'class);
          procedure affich_div (emet : access gtk_widget_record'class);      
          procedure effacer (emet : access gtk_widget_record'class);
          procedure aff_resultat (emet : access gtk_widget_record'class);
    --        procedure spliter_gch (UStr : unbounded_string);
    --        procedure spliter_drt (UStr : unbounded_string);
    --        procedure spliter_sig (UStr : unbounded_string);
          function spliter_gch (UStr : unbounded_string) return integer;
          function spliter_drt (UStr : unbounded_string) return integer;
          function spliter_sig (UStr : unbounded_string) return character;
          function operation return integer;
          function recup_resultat return unbounded_string;
          function compte_elem return integer;
          function recup_string return string;
     
       end aff_outils;
     
       --------------------------------
       -- package aff_outils (corps) --
       --------------------------------
     
       package body aff_outils is
     
          -- Actions --
          procedure affich_plus (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "+", pos);
          end affich_plus;
     
          procedure affich_moins (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "-", pos);
          end affich_moins;
     
          procedure affich_mul (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "*", pos);
          end affich_mul;
     
          procedure affich_div (emet : access gtk_widget_record'class) is
          begin
             insert_text(Ecran, "/", pos);
          end affich_div;
     
     
          procedure effacer (emet : access gtk_widget_record'class) is
          begin
             delete_text(Ecran, 0, pos);
          end effacer;
     
    --        procedure spliter_gch (UStr : unbounded_string) is
    --           int_gch : integer;
    --        begin
    --           int_gch := integer'value(chaine_gauche(UStr));
    --           empiler(int_gch);
    --        end spliter_gch;
    --  
    --        procedure spliter_drt (UStr : unbounded_string) is
    --           int_drt : integer;
    --        begin
    --           int_drt := integer'value(chaine_droite(UStr));
    --           empiler(int_drt);
    --        end spliter_drt;
    --  
    --        procedure spliter_sig (UStr : unbounded_string) is
    --           char_sig : character;
    --        begin
    --           char_sig := ada.strings.unbounded.element(Ustr, cpt_elem_gch(UStr)+1);
    --           empiler_sig(char_sig);
    --        end spliter_sig;
     
          function spliter_gch (UStr : unbounded_string) return integer is
             int_gch : integer;
          begin
             int_gch := integer'value(chaine_gauche(UStr));
             return int_gch;
          end spliter_gch;
     
          function spliter_drt (UStr : unbounded_string) return integer is
             int_drt : integer;
          begin
             int_drt := integer'value(chaine_droite(UStr));
             return int_drt;
          end spliter_drt;
     
          function spliter_sig (UStr : unbounded_string) return character is
             char_sig : character;
          begin
             char_sig := ada.strings.unbounded.element(Ustr, cpt_elem_gch(UStr)+1);
             return char_sig;
          end spliter_sig;
     
          function operation return integer is
             Uchaine : unbounded_string := ada.strings.unbounded.to_unbounded_string(get_chars(Ecran, 0, pos));
             gauche, droite, resultat : integer;
             sig : character;
          begin
             gauche := spliter_gch(Uchaine);
             droite := spliter_drt(Uchaine);
             sig := spliter_sig(Uchaine);
             if sig = '+' then
                resultat := gauche + droite;
             elsif sig = '-' then
                resultat := gauche - droite;
             elsif sig = '*' then
                resultat := gauche * droite;
             else
                resultat := 0;
             end if;
    --  --           return resultat;
    --           case sig is
    --              when '+' => resultat := gauche + droite;
    --              when '-' => resultat := gauche - droite;
    --              when '/' => resultat := gauche / droite;
    --              when '*' => resultat := gauche * droite;
    --              when others => null;
    --           end case;
             return resultat;
          end operation;
     
          function recup_resultat return unbounded_string is
             int_ustr : unbounded_string;
             resultat : integer;
          begin
             resultat := operation;
             int_ustr := ada.strings.unbounded.to_unbounded_string(integer'image(resultat));
             return int_ustr;
          end recup_resultat;
     
          function compte_elem return integer is
             long : integer := explode(recup_resultat);
          begin
             return long;
          end compte_elem;
     
          function recup_string return string is
             chaine : string (1 .. compte_elem);
          begin
             chaine := ada.strings.unbounded.to_string(recup_resultat);
             return chaine;
          end recup_string;
     
          procedure aff_resultat (emet : access gtk_widget_record'class) is
             chaine : string (1 .. compte_elem);
          begin
             chaine := recup_string;
             insert_text(affich_result, chaine, pos);
          end aff_resultat;
     
       end aff_outils;
     
     
     
       package traitement is new callback (gtk_widget_record);
       package traitement_tools is new callback (gtk_widget_record);
    --     type String_Ptr is access all String;
    --
    --     procedure Affich (Emet : access Gtk_Widget_Record'Class;
    --                     Data : String_Ptr) is
    --     begin
    --        Insert_Text(Ecran, Data.all , Pos);
    --     end affich;
    --
    --     package Traitement is new Gtk.Handlers.User_Callback
    --       (Widget_Type => Gtk_Widget_Record,
    --        User_Type   => String_Ptr);
     
     
     
       use aff_outils;
     
    begin
     
    init;
     
       -- Création de la fenetre
       gtk_new(fenetre, window_toplevel);
       set_size_request(fenetre, 400, 300);
       set_position(fenetre, win_pos_center);
     
       gtk_new(Table, 21, 25, true);
       add(fenetre, Table);
     
     
     
       -- Création d'un Frame "Affichage", suivi
       -- de la Création de l'écran d'affichage
       gtk_new(Frame_affich, "Affichage");
       attach_defaults(Table, Frame_affich, 1, 24, 1, 6);
     
       gtk_new(Ecran);
       attach_defaults(Table, Ecran, 2, 9, 2, 3);
       set_has_frame (Ecran, false);
       set_editable (Ecran, False);
     
    --     gtk_new(Ecran2);
    --     attach_defaults(Table, Ecran2, 9, 12, 2, 3);
    --     set_has_frame (Ecran2, false);
    --     set_editable (Ecran2, False);
    --
    --     gtk_new(Ecran3);
    --     attach_defaults(Table, Ecran3, 12, 19, 2, 3);
    --     set_has_frame (Ecran3, false);
    --     set_editable (Ecran3, False);
     
       gtk_new(Affich_result);
       attach_defaults(Table, Affich_result, 2, 19, 4, 5);
       set_editable (Affich_result, False);
     
       gtk_new(btn_exe, "EXE");
       attach_defaults(Table, btn_exe, 20, 23, 2, 5);
       traitement_tools.connect (btn_exe, "clicked", traitement_tools.to_marshaller(aff_outils.aff_resultat'access));
     
     
       -- Création des boutons du frame "Opérations" - opérations usuelles
       -- suivi de la création des boutons relatifs à ce frame
       gtk_new(Frame_ope, "Operations");
       attach_defaults(Table, frame_ope, 1, 12, 13, 20);
     
       gtk_new(btn_plus, "+");
       attach_defaults(Table, btn_plus, 3, 5, 15, 17);
       traitement_tools.connect (btn_plus, "clicked", traitement_tools.to_marshaller(aff_outils.affich_plus'access));
     
       gtk_new(btn_moins, "-");
       attach_defaults(Table, btn_moins, 5, 7, 15, 17);
       traitement_tools.connect (btn_moins, "clicked", traitement_tools.to_marshaller(aff_outils.affich_moins'access));
     
       gtk_new(btn_mul, "*");
       attach_defaults(Table, btn_mul, 7, 9, 15, 17);
       traitement_tools.connect (btn_mul, "clicked", traitement_tools.to_marshaller(aff_outils.affich_mul'access));
     
       gtk_new(btn_div, "/");
       attach_defaults(Table, btn_div, 9, 11, 15, 17);
       traitement_tools.connect (btn_div, "clicked", traitement_tools.to_marshaller(aff_outils.affich_div'access));
     
     
       -- Création du Frame "Nombres" suivi de la
       -- création des boutons "virgule" et "puissance de 10", suivi de
       -- la création d'une boucle pour générer les x boutons chiffres
       gtk_new(Frame_nomb, "Chiffres");
       attach_defaults(Table, Frame_nomb, 13, 24, 7, 20);
     
       gtk_new(btn_clear, "C");
       attach_defaults(Table, btn_clear, 20, 23, 17, 19);
       traitement_tools.connect (btn_clear, "clicked", traitement_tools.to_marshaller(aff_outils.effacer'access));
     
       gtk_new(bouton0, "0");
       attach_defaults(Table, bouton0, g(0), d(0), h(0), b(0));
       traitement.connect (bouton0, "clicked", traitement.to_marshaller(aff_chiffres.affich0'access));
     
       gtk_new(bouton1, "1");
       attach_defaults(Table, bouton1, g(1), d(1), h(1), b(1));
       traitement.connect (bouton1, "clicked", traitement.to_marshaller(aff_chiffres.affich1'access));
     
       gtk_new(bouton2, "2");
       attach_defaults(Table, bouton2, g(2), d(2), h(2), b(2));
       traitement.connect (bouton2, "clicked", traitement.to_marshaller(aff_chiffres.affich2'access));   
     
    --     for J in Bouton'Range loop
    --        Gtk_New(Bouton(J), Integer'Image(J));
    --        Traitement.Connect(Bouton(J),
    --                           "clicked",
    --                           Traitement.To_Marshaller(Affich'Access),
    --                           new String'(get_label(bouton(J)))); --Integer'Image(J)));
    --     end loop;
    --
    --
    --     for J in bouton'range loop
    --        attach_defaults(Table, bouton(J), G(J), D(J), H(J), B(J));
    --     end loop;
     
    show_all(fenetre);
    main;
     
    end cessai2;
    C'est un projet que je dois rendre pour la fin du mois, mais je ne le sens pas très bien !!!
    Images attachées Images attachées  

Discussions similaires

  1. Réponses: 2
    Dernier message: 01/12/2012, 14h53
  2. Réponses: 2
    Dernier message: 24/04/2008, 15h31
  3. Ou placer ces Raise Error
    Par kramer Mc Barreth dans le forum SQL
    Réponses: 5
    Dernier message: 02/01/2008, 21h02
  4. Réponses: 0
    Dernier message: 12/12/2007, 21h10
  5. Problème constraint error
    Par Vivian Pennel dans le forum Ada
    Réponses: 13
    Dernier message: 16/11/2006, 16h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo