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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2f343e3986ead102 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nlpi057.nbdc.sbc.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: String declaration and initialization Date: Thu, 22 May 2008 13:11:20 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <05bce551-cd98-417c-8664-847b29124c19@l64g2000hse.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: pcls6.std.com 1211476280 17476 192.74.137.71 (22 May 2008 17:11:20 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 22 May 2008 17:11:20 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:a9w24xg1pNFhPgtwL5NZ+AqgovI= Xref: g2news1.google.com comp.lang.ada:293 Date: 2008-05-22T13:11:20-04:00 List-Id: S�bastien writes: > But you give me an Idea : > declare > buffer: access String; > Free_String is new Unchecked_Deallocation(String, access all String); > begin > case SomeTest is > case TEST1 => > buffer := new String("Test1"); > case TEST2 => > buffer := new String("Test2"); > end case; > MyTreatment1(buffer.all, buffer.all'Size); > MyTreatment2(buffer.all, buffer.all'Size); > MyTreatment3(buffer.all, buffer.all'Size); > end; > > but it doesn't work of course since I can't create with new an > unconstrained object. Sure you can: buffer := new String'("Test1"); ^ | Note tick mark! << new String("Test1"); >> does not make sense. You have to use a qualified expression (as above) or a constrained subtype, as in: new String(1..10) You didn't call Free_String, by the way. Think about whether you want to call it in case of exception! - Bob