home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada
- Path: sparky!uunet!jeol!jam
- From: jam@jeol.com
- Subject: Re: ADA question
- Message-ID: <jam.714606087@jeol>
- Keywords: Strings, Packages
- Organization: JEOL USA, Inc.
- References: <1992Aug23.102056.19487@alf.uib.no>
- Date: Sun, 23 Aug 1992 21:41:27 GMT
- Lines: 49
-
- In <1992Aug23.102056.19487@alf.uib.no> sahni@eik.ii.uib.no (Sahni Daljeet Singh) writes:
-
- >I am beginning to learn Ada and am stuck at a point. The question is as
- >follows:
-
- >I have a function in a package A which returns string. I am using
- >that function in another package B and try to give the value returned
- >by that function to a variable (which has been declared in package B).
- >The variable is of type string (1 .. max) initialised to empty string.
- >My program simple raises an exception.
- >Could it be that the array size is different for the variable and the value
- >returned by the function. The function can return a string of different
- >sizes. Can somebody give help me out?
-
- You are correct, the strings must be of the same size... There are
- various ways that you can solve this problem. For example :
-
- o. Make a subtype that the function returns and the variable can be
- declared with.
- subtype MY_STRING is STRING(1..max);
- ...
- x : MY_STRING;
- ...
- x := the_func( whatever );
- ...
- o. Make a function/procedure which the result of the first function is
- passed to and then deal with the result.
- procedure MY_PROC( value : STRING ) is
- begin
- -- do something with value
- -- 'first, 'last, 'range, 'length will all work on value.
- end MY_PROC;
- ....
- my_proc( my_func( whatever ) );
- ...
- o. Change the function to a procedure which then returns the size to the
- user.
- o. It you need variable length strings, look in the library for a VSTRINGS
- package that might make the problem a lot easier. VERDIX supplies
- one. Basically a record containing a string and a length, often times
- dynamic to allow for widely sized strings.
-
- Good luck, If none of these help then define your problem more exactly.
-
- --
-
- John Malcolmson
- (malcolmson@jeol.com)
-
-