From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: HELP | function Is_Open (File : File_Type) return Boolean; package ada.text_io
Date: Mon, 26 Oct 2015 22:40:40 +0200
Date: 2015-10-26T22:40:40+02:00 [thread overview]
Message-ID: <d97he8Fi0niU1@mid.individual.net> (raw)
In-Reply-To: <7d129899-8c22-46a4-b94d-bc746c7fc458@googlegroups.com>
On 15-10-26 12:21 , comicfanzine@gmail.com wrote:
> Can someone please post a simple code in which this function is used , i'm lost , thanks .
The following program can be run with or without command-line arguments.
If, and only if, there are command-line arguments, the program creates
and writes some text to a file called my_log_file.txt.
with Ada.Command_Line;
with Ada.Text_IO;
procedure Ex_Is_Open
is
Log_File : Ada.Text_IO.File_Type;
--
-- File for log output.
-- Created only if the program has command-line arguments.
procedure Log (Text : in String)
--
-- Log the Text, if the Log_File is open.
--
is
begin
if Ada.Text_IO.Is_Open (Log_File) then
Ada.Text_IO.Put_Line (Log_File, Text);
end if;
end Log;
begin -- Ex_Is_Open
Log ("This will not appear in the log.");
if Ada.Command_Line.Argument_Count > 0 then
Ada.Text_IO.Put_Line ("Creating log file my_log_file.txt.");
Ada.Text_IO.Create (
File => Log_File,
Name => "my_log_file.txt",
Mode => Ada.Text_IO.Out_File);
end if;
Log ("This will appear iff there are command-line arguments.");
if Ada.Text_IO.Is_Open (Log_File) then
-- We close the log.
-- Trying to Close the Log_File if it is not open
-- raises the exception Ada.Text_IO.Status_Error.
Ada.Text_IO.Close (Log_File);
end if;
Log ("This will not appear in the log.");
end Ex_Is_Open;
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
next prev parent reply other threads:[~2015-10-26 20:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-26 10:21 HELP | function Is_Open (File : File_Type) return Boolean; package ada.text_io comicfanzine
2015-10-26 20:40 ` Niklas Holsti [this message]
2015-10-27 7:48 ` comicfanzine
2015-10-27 11:23 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox