From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,e96fdf9557794655 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!v15g2000prn.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Conversions Date: Mon, 26 Oct 2009 13:19:10 -0700 (PDT) Organization: http://groups.google.com Message-ID: <0654c44b-6db9-4304-b3c0-5cd7b870eb4c@v15g2000prn.googlegroups.com> References: <4acc8c20$0$284$14726298@news.sunsite.dk> <4acdb7aa$0$283$14726298@news.sunsite.dk> <1256585268.3272.14.camel@HERMES> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1256588351 22526 127.0.0.1 (26 Oct 2009 20:19:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 26 Oct 2009 20:19:11 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v15g2000prn.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8798 Date: 2009-10-26T13:19:10-07:00 List-Id: On Oct 26, 12:27=A0pm, Bruno wrote: > Hi all, > > 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 returns a string whose first character is a space if the argument is not negative. So if N =3D 12, then Integer'Image(N) =3D " 12"---i.e. 3 characters. That won't fit in the two-character slice you're trying to put it in, so you get a Constraint_Error. But just getting rid of the space doesn't work either. If N =3D 1, then Integer'Image(N) =3D " 1", and if you were able to trim off the space, the result would be "1", and you'd still get a Constraint_Error. When you assign a slice like this, the left and right sides must be the same length. There are a number of ways to do what you want, but I'd suggest looking at the Ada.Strings.Fixed package, especially the Move, Trim, and Tail routines. Hope this helps, -- Adam