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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,691bbbf0ab0cc67e X-Google-Attributes: gid103376,public From: "Nick Roberts" Subject: Re: [Q] Returning Strings From A Function Date: 1997/04/08 Message-ID: <01bc43b8$a4c441a0$09f682c1@xhv46.dial.pipex.com>#1/1 X-Deja-AN: 231427894 References: <33454165.1658515@news.demon.co.uk> <33478738.2129057@news.demon.co.uk> <01bc42af$e32e3ea0$90f482c1@xhv46.dial.pipex.com> Organization: UUNet PIPEX server (post doesn't reflect views of UUNet PIPEX) Newsgroups: comp.lang.ada Date: 1997-04-08T00:00:00+00:00 List-Id: Robert A Duff wrote in article ... > In article <01bc42af$e32e3ea0$90f482c1@xhv46.dial.pipex.com>, > Nick Roberts wrote: > > FS: Filename_String := ""; -- unconstrained type, so must be initialised > > FS is forever constrained to length zero. > > > FS := Text_IO.Name(F); -- constraint error raised if longer than 12 > > No, this will raise C_E, unless the name is of length zero. > > Ada's built-in arrays cannot change size. Argh! The embarrassment! Sudden brainstorm, Bob (my excuse being that I am using a lot of different languages at the moment (pretty feeble, eh?)). Anyway, what I _should_ have written was this... declare F: Text_IO.File_Type; ... type Filename_String is array (1..12 range <>) of Character; type Filename_Ref is access Filename_String; ... S: Filename_Ref; ... begin ... S := new Filename_String'(Text_IO.Name(F)); -- constraint error raised if name longer than 12 chars ... Text_IO.Put("Name of file is: "+String(S.all)); -- note the need to dereference and convert ... end; John: I hope I did not end up confusing you. Many apologies. The above will actually work, and will hopefully be a relatively simple solution to your problem. Nick.