From: darek <darek.maksimiuk@gmail.com>
Subject: Get_Immediate has raised CONSTRAINT_ERROR : s-wchcnv.adb:207 explicit raise
Date: Wed, 18 Feb 2015 09:29:50 -0800 (PST)
Date: 2015-02-18T09:29:50-08:00 [thread overview]
Message-ID: <234cdad3-5c41-4b0d-b611-01c53273cb7f@googlegroups.com> (raw)
Dear All,
reading from a keyboard keys such as arrow keys, PgUp, PgDn, etc. seems to be a small challenge in Ada. For this purpose one of the Get_Immediate procedures from the Ada.Text_IO shall be used. For the keyboard we can use either
- procedure Get_Immediate (Item : out Character)
or
- procedure Get_Immediate (Item : out Character; Available : out Boolean)
When I have used the Get_Immediate procedure with the extra boolean parameter, it generates the constraint error for:
- all arrow keys, PgUp, PgDn
- [ character from the keyboard !!!!
Is this a feature or a bug. How pressing a legal key can cause such a weird result?
The Get_Immediate procedure without the boolean parameter works fine but it waits for a key to be pressed.
System: Linux Testpc 3.11-2-amd64 #1 SMP Debian 3.11.8-1 (2013-11-13) x86_64 GNU/Linux (running as a guest inside the VirtualBox VM)
Compiler:gcc version 4.7.4 20140401 for GNAT GPL gpl-2014 (20140405) (GCC)
Any ideas how to avoid the problem with this exception? Am I missing something?
Cheers,
Darek
The code:
with Ada.Text_IO;
procedure TestKbd is
package tIO renames Ada.Text_IO;
procedure Test_Get_Immediate_No_Avail is
Char : Character;
begin
loop -- an infinite loop
tIO.Put_Line("Read key:");
--| Here Get_Immediate is waiting for the input
tIO.Get_Immediate(Char);
tIO.Put_Line("Char ==>" & Character'Image(Char) & " code:" & Integer'Image(Character'Pos(Char)));
delay (0.1);
end loop;
end Test_Get_Immediate_No_Avail;
procedure Test_Get_Immediate_With_Avail is
Char : Character;
Avail : Boolean;
begin
loop -- an infinite loop
tIO.Put_Line("Read key: ");
tIO.Get_Immediate(Char, Avail);
if Avail then
tIO.Put_Line("Char ==>" & Character'Image(Char) & " code:" & Integer'Image(Character'Pos(Char)));
end if;
delay (1.0);
end loop;
end Test_Get_Immediate_With_Avail;
begin
Test_Get_Immediate_With_Avail;
--Test_Get_Immediate_No_Avail;
end TestKbd;
next reply other threads:[~2015-02-18 17:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-18 17:29 darek [this message]
2015-02-18 18:34 ` Get_Immediate has raised CONSTRAINT_ERROR : s-wchcnv.adb:207 explicit raise Dmitry A. Kazakov
2015-02-18 19:34 ` darek
2015-02-18 20:36 ` Dmitry A. Kazakov
2015-02-18 21:19 ` darek
2015-02-18 21:44 ` Dmitry A. Kazakov
2015-02-18 22:09 ` Georg Bauhaus
2015-02-18 20:16 ` Simon Wright
2015-02-18 20:34 ` darek
2015-02-19 21:37 ` Björn Lundin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox