From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org>
Subject: Re: Conversions
Date: Mon, 26 Oct 2009 13:09:45 -0700
Date: 2009-10-26T13:09:45-07:00 [thread overview]
Message-ID: <hc4vma$e65$1@news.tornevall.net> (raw)
In-Reply-To: <1256585268.3272.14.camel@HERMES>
Bruno wrote:
>
> I have a little problem with a function that "convert" a date, that is a
> record type, into a string. To do this I'm using "image" attribute how
> can you see in the following code
>
> http://paste.ideaslabs.com/show/5KEJUGcDF
>
> but when run the program and the function is executed a get an
> "constraint error". The compiler show me a message that say that the
> size is too long but I don't know what to do.
'Image for an integer type returns the shortest string necessary to represent
the value, with ' ' added to the front for a positive value and '-' for a
negative value.
Thus we can get
6 => " 6"
-6 => "-6"
10 => " 10"
-10 => "-10"
For your application (date image), 2-digit day and month numbers are likely;
their 'Image will not fit in 2 characters.
You can save the 'Image and decide what to do with it:
declare
Day_Image : constant String := Integer'Image (F.Dia);
begin
if F.Dia < 10 then
S (1) := '0';
S (2) := Day_Image (Day_Image'Last);
else
S (1 .. 2) := Day_Image (Day_Image'Last - 1 .. Day_Image'Last);
end if;
end;
You can also look at the operations in Ada.Text_IO.Integer_IO that write to a
String parameter.
--
Jeff Carter
"We call your door-opening request a silly thing."
Monty Python & the Holy Grail
17
next prev parent reply other threads:[~2009-10-26 20:09 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-07 12:40 Ada.Directories.Base_Name and dot files
2009-10-07 14:46 ` Yannick Duchêne Hibou57
2009-10-07 17:06 `
2009-10-07 14:52 ` Adam Beneschan
2009-10-07 17:06 `
2009-10-07 15:10 ` Adam Beneschan
2009-10-07 15:37 ` Yannick Duchêne Hibou57
2009-10-11 2:39 ` Randy Brukardt
2009-10-07 20:11 `
2009-10-08 9:39 ` Stephen Leake
2009-10-08 9:58 `
2009-10-26 19:26 ` Type casting Bruno
2009-10-26 20:02 ` Jeffrey R. Carter
2009-10-26 20:09 ` Adam Beneschan
2009-10-26 19:27 ` Conversions Bruno
2009-10-26 20:09 ` Jeffrey R. Carter [this message]
2009-10-26 20:19 ` Conversions Adam Beneschan
-- strict thread matches above, loose matches on Subject: below --
2000-03-16 0:00 Conversions Karlene Johnson
2000-03-16 0:00 ` Conversions Marin D. Condic
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox