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,WEIRD_PORT 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!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: function Is_Open (File : File_Type) return Boolean; :Text_io Date: Mon, 26 Oct 2015 18:01:57 +0000 Organization: A noiseless patient Spider Message-ID: References: <75dd21a2-9265-44e4-a4d4-e2d96ffdecb1@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="2d7699570724a9a82a760842267e2c56"; logging-data="24467"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19n7p2IdmB92prgWwm7FSm/KYCCdvvV+h4=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (darwin) Cancel-Lock: sha1:614tnA3TYogYMvarrKYOJKS+irg= sha1:dnmBlg2ieg+AaO5fcoTLM6B0lyQ= Xref: news.eternal-september.org comp.lang.ada:28058 Date: 2015-10-26T18:01:57+00:00 List-Id: comicfanzine@gmail.com writes: > Thanks fot link . > > I want to create+open a file then use Is_Open , if the file have been create i want to put some text + the value of Is_Open(should be TRUE) . > > There is french in the code : > > [code]WITH Ada.Text_IO ; USE Ada.Text_IO ; > > PROCEDURE TestFichier IS > > MonFichier : File_type ; > > BEGIN > Create( MonFichier,Name => "clone.adb"); > open(MonFichier,In_file,"clone.adb") ; > if Is_Open(MonFichier) and MonFichier = true > then put("Le fichier , ouvert ? : ",MonFichier); > end if; > END TestFichier ;[/code] Compiling this with listing (gnatmake -gnatl testfichier.adb) gives 3. PROCEDURE TestFichier IS 4. 5. MonFichier : File_type ; 6. 7. BEGIN 8. Create( MonFichier,Name => "clone.adb"); 9. open(MonFichier,In_file,"clone.adb") ; 10. if Is_Open(MonFichier) and MonFichier = true | >>> invalid operand types for operator "=" >>> left operand has private type "Ada.Text_Io.File_Type" >>> right operand has type "Standard.Boolean" 11. then put("Le fichier , ouvert ? : ",MonFichier); 1 3 >>> no candidate interpretations match the actuals: >>> too many arguments in call to "put" >>> expected private type "Ada.Text_Io.File_Type" >>> found a string type >>> ==> in call to "Put" at a-textio.ads:241 >>> ==> in call to "Put" at a-textio.ads:207 12. end if; 13. END TestFichier ; First, the compiler messages: Line 10 ------- Is_Open returns Boolean, and MonFichier is a File_Type and can't be compared to Boolean (in fact, it's limited private, so it can't by default be compared to anything!) so I think you just meant if Is_Open (MonFichier) Line 11 ------- You have the arguments the wrong way round. You could use named parameter association if you insist on this order, Put (Item => "Le fichier , ouvert ? : ", File => MonFichier); ============================== Second, the semantic problems: Create at line 8 will either result in an opened writable file (MonFichier) or will raise an exception if the file already existed. If you get to line 9 (i.e. the Create was successful) you will get an exception because the file is already open. If you were to get to line 10, Is_Open would have to return True. If you were to get to line 11 having executed line 9, you would get an exception because you opened MonFichier read-only.