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,8a34575d5eb275cb X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!y7g2000yqa.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Load an object from a file Date: Thu, 9 Apr 2009 14:22:24 -0700 (PDT) Organization: http://groups.google.com Message-ID: <45060408-3467-4f54-b7ab-8d60e291b3ba@y7g2000yqa.googlegroups.com> References: <49d5fa88$0$2862$ba620e4c@news.skynet.be> <443d72ca-5bbd-46a3-84c6-e8bd984e5b80@k41g2000yqh.googlegroups.com> <49de5b78$0$2853$ba620e4c@news.skynet.be> NNTP-Posting-Host: 94.108.151.159 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1239312144 10226 127.0.0.1 (9 Apr 2009 21:22:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 9 Apr 2009 21:22:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: y7g2000yqa.googlegroups.com; posting-host=94.108.151.159; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.7) Gecko/2009030810 Iceweasel/3.0.7 (Debian-3.0.7-1),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:4459 Date: 2009-04-09T14:22:24-07:00 List-Id: On Apr 9, 10:32=A0pm, Olivier Scalbert wrote: > Hi, > > I still have one question ... > How can I implement the Load_Class procedure that will use the Input > function? > I do not know how to get the needed stream from a given file name. > And I do not know how to define the Class_File_Structure result (I get > an unconstrained subtype (need initialization)). [...] > package body jvm is [...] > =A0 =A0 =A0procedure Load_Class(File_Name: String) is > > =A0 =A0 =A0 =A0 =A0Class_File_Structure: Class_File_Structure_T; -- (unco= nstrained > subtype (need initialization) > =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0Put_Line(File_Name); > > =A0 =A0 =A0 =A0 =A0Class_file_Structure :=3D Input(Stream ???); > > =A0 =A0 =A0end Load_Class; [...] > end jvm; Because Class_File_Structure_T is unconstrained and needs initialization, you cannot use a procedure to load one: out parameters don't work, and the procedure cannot write into a variable because you can't declare a variable without initializing it. So, here is a possible solution replacing your procedure with a function: with Ada.Streams.Stream_IO; ... function From_File (File_Name : String) return Class_File_Structure_T is File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File, File_Mode =3D> Ada.Streams.Stream_IO.In_File, Name =3D> File_Name); declare Result : constant Class_File_Structure_T :=3D Class_File_Structure_T'Input (Ada.Streams.Stream_IO.Stream (File)); begin Ada.Streams.Stream_IO.Close (File); return Result; end; end From_File; HTH -- Ludovic Brenta.