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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: HELP | function Is_Open (File : File_Type) return Boolean; package ada.text_io Date: Mon, 26 Oct 2015 22:40:40 +0200 Organization: Tidorum Ltd Message-ID: References: <7d129899-8c22-46a4-b94d-bc746c7fc458@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net z0Qm9Y+omwbfNRLrPZfvVQXJHAAywJc1mtDQezOoIUilQEs/ep Cancel-Lock: sha1:dqLU8rPPRQzfH8n05wOQvFoLITU= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: <7d129899-8c22-46a4-b94d-bc746c7fc458@googlegroups.com> Xref: news.eternal-september.org comp.lang.ada:28062 Date: 2015-10-26T22:40:40+02:00 List-Id: 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 . @ .