comp.lang.ada
 help / color / mirror / Atom feed
* An elementary XFORMS problem
@ 1999-12-29  0:00 creator
  1999-12-29  0:00 ` Ted Dennison
  0 siblings, 1 reply; 2+ messages in thread
From: creator @ 1999-12-29  0:00 UTC (permalink / raw)


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've tried with different Stringsizes and without the FL_NULL's.
I hope someone can help me.
Mvh
Pehr


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: An elementary XFORMS problem
  1999-12-29  0:00 An elementary XFORMS problem creator
@ 1999-12-29  0:00 ` Ted Dennison
  0 siblings, 0 replies; 2+ messages in thread
From: Ted Dennison @ 1999-12-29  0:00 UTC (permalink / raw)


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






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-12-29  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-29  0:00 An elementary XFORMS problem creator
1999-12-29  0:00 ` Ted Dennison

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