From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Load an object from a file
Date: Thu, 9 Apr 2009 14:22:24 -0700 (PDT)
Date: 2009-04-09T14:22:24-07:00 [thread overview]
Message-ID: <45060408-3467-4f54-b7ab-8d60e291b3ba@y7g2000yqa.googlegroups.com> (raw)
In-Reply-To: 49de5b78$0$2853$ba620e4c@news.skynet.be
On Apr 9, 10:32 pm, Olivier Scalbert <olivier.scalb...@algosyn.com>
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
[...]
> procedure Load_Class(File_Name: String) is
>
> Class_File_Structure: Class_File_Structure_T; -- (unconstrained
> subtype (need initialization)
> begin
> Put_Line(File_Name);
>
> Class_file_Structure := Input(Stream ???);
>
> end 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 =>
Ada.Streams.Stream_IO.In_File,
Name => File_Name);
declare
Result : constant Class_File_Structure_T :=
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.
next prev parent reply other threads:[~2009-04-09 21:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-03 12:01 Load an object from a file Olivier Scalbert
2009-04-03 13:07 ` Niklas Holsti
2009-04-03 13:37 ` Ludovic Brenta
2009-04-03 15:19 ` Olivier Scalbert
2009-04-03 16:08 ` Georg Bauhaus
2009-04-03 16:22 ` Ludovic Brenta
2009-04-03 16:41 ` Olivier Scalbert
2009-04-03 16:46 ` Adam Beneschan
2009-04-03 20:22 ` Ludovic Brenta
2009-04-09 20:32 ` Olivier Scalbert
2009-04-09 21:22 ` Ludovic Brenta [this message]
2009-04-09 22:22 ` Olivier Scalbert
2009-04-19 13:08 ` Olivier Scalbert
2009-04-19 19:52 ` Ludovic Brenta
2009-04-19 20:27 ` Gautier
2009-04-03 13:41 ` Thomas Løcke
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox