comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: Re: An elementary XFORMS problem
Date: 1999/12/29
Date: 1999-12-29T00:00:00+00:00	[thread overview]
Message-ID: <386A3730.B35DF3DD@telepath.com> (raw)
In-Reply-To: 15f5621a.f9b8c972@usw-ex0102-016.remarq.com

creator wrote:

> I'm trying to make a procedure using XFORMS function FL_SHOW_FSELECTOR.
> My procedure looks like this:
>
> procedure Pehr(O:access FL_OBJECT;ID:Long_Integer) is
> Streng:String(1..10);
> begin
> --Nine blanks
> Streng:="         "&FL_NuLL;
> Streng:=FL_SHOW_FSELECTOR(" "&FL_NULL," "&FL_NULL,"*"&FL_NULL,"
> "&FL_NULL);
> end Pehr;
>
> When i run it ,i get an "raised CONSTRAINT_ERROR"

I don't know what XFORMS is. But this looks like a pretty basic error. If you
are going to assign data into a string (or any array type for that matter) you
have to assign *all* the elements at once (and no more), or use a slice of the
string. Assuming that FL_Nul is one character, the first assignment is 10
characters, which is OK. But the second one appears to be only 8. I don't know
what FL_SHOW_FSELECTOR does to it. But unless it tacks 2 more characters on and
returns the result, you are in trouble. Attempting to assign 8 characters into a
10 character string will cause Constraint_Error to be raised.

You could do a:
   Streng(1..8) :=  FL_SHOW_FSELECTOR(" "&FL_NULL," "&FL_NULL,"*"&
   FL_NULL," "&FL_NULL);

But its better to set the length based on the length of the thing you are
copying:
   Streng(1.. FL_SHOW_FSELECTOR(" "&FL_NULL," "&FL_NULL,"*"&
     FL_NULL," "&FL_NULL)'length) :=  FL_SHOW_FSELECTOR(" "&FL_NULL," "&
     FL_NULL,"*"&FL_NULL," "&FL_NULL);

Even better is to only call the function once, so there's no typo issues in the
parameters you send to it:
   Fl_Show_Value : constant String :=  FL_SHOW_FSELECTOR(" "&FL_NULL," "&
     FL_NULL,"*"& FL_NULL," "&FL_NULL);
begin
   Streng(1..Fl_Show_Value'length) := Fl_Show_Value;

Best yet would be to just initialize the string with the value you want it to
have, rather than try to modify it on the fly:
   Streng : constant String := FL_SHOW_FSELECTOR(" "&FL_NULL," "&FL_NULL,"*"&
     FL_NULL," "&FL_NULL);
begin

If what you posted isn't the whole story and you do need to modify it on the
fly, you should read through the Ada.Strings packages to see easier/safer ways
of modifying strings.

--
T.E.D.

Home - mailto:dennison@telepath.com
WWW  - http://www.telepath.com/dennison/Ted/TED.html






      reply	other threads:[~1999-12-29  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-29  0:00 An elementary XFORMS problem creator
1999-12-29  0:00 ` Ted Dennison [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox