[gtkada] simple gtk_editable question

Siddhartha Ray SiddharthaR at TucsonEmbedded.com
Wed Jan 9 21:18:58 CET 2002


Send it to the gnat list.

The problem is NAME_TYPE is constrained to 40 characters but get_chars
returns a general string type.

Therefore unless get_chars returns exactly 40 characters you will get a
constaint error.

Easiest solution:

with Ada.Strings.Fixed;
use Ada.Strings.Fixed;

with Ada.Text_Io;
use Ada.Text_Io;
procedure Easiest_Solution is 

   -- Emulates the get_chars function --
   function Get_Chars (
         X : Integer ) 
     return String is 
   begin
      case X is
         when 1 =>
            return "hello";
         when 2 =>
            return "world";
         when others =>
            return " ";
      end case;
      return " ";
   end Get_Chars;


   L : constant := 40;  
   subtype Name_Type is String(1.. L);
   Temprorary_String : String    := Get_Chars (1);  
   Actual_String     : Name_Type;  
begin
   if Temprorary_String'Length < L then
      Actual_String := Temprorary_String & (L - Temprorary_String'Length) *
         " ";
   elsif Temprorary_String'Length > L then
      Actual_String := Temprorary_String (Temprorary_String'First ..
         Temprorary_String'First + L - 1);
   else
      Actual_String := Temprorary_String;
   end if;
   Put_Line(Actual_String);
end Easiest_Solution;

The above program compensates for the loss/abundance of characters in the
actual string by either
appending or removing excess characters.

Notice I also had to with the Ada.Strings.Fixed package for the * function
for strings.


Hope this helps,
There are other options too like using Unbounded strings. If you send your
question to gnatlist or comp.lang.ada you'll get all the Ada related
answers.

-Sid

-----Original Message-----
From: Arnaud Charlet [mailto:charlet at ACT-Europe.FR]
Sent: Wednesday, January 09, 2002 12:22 PM
To: gtkada at lists.act-europe.fr
Subject: Re: [gtkada] simple gtk_editable question


>   I need to maintain the original code base which defines NAME as the
> subtype NAME_TYPE and NAME_TYPE as a string of (1..40)...  could it have
> something to do with the use of subtypes?   To simplify things for testing
> purposes I removed all that and now have a simple bounded string called
> holder which I'm trying to get the value from the entry. I'm still getting
a
> constraint error raised on the 'get_chars' line.  I know I know, probably
a
> simple Ada problem...  Anybody?

Yes, this really is getting off topic. I think people gave you enough
general
Ada help here so that you can get a sense that your problem isn't related
to GtkAda. If you need more help, I'd suggest that you ask your question to
a
general Ada forum such as comp.lang.ada, or that you contact your compiler
vendor which will be happy to help.

Regards,

Arno

_______________________________________________
gtkada mailing list
gtkada at lists.act-europe.fr
http://lists.act-europe.fr/mailman/listinfo/gtkada




More information about the gtkada mailing list