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-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!novso.com!news.skynet.be!195.238.0.222.MISMATCH!newsspl501.isp.belgacom.be!tjb!not-for-mail Date: Sat, 30 May 2009 13:41:41 +0200 From: Olivier Scalbert User-Agent: Thunderbird 2.0.0.21 (X11/20090409) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Question on Controlled types Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4a211b98$0$2862$ba620e4c@news.skynet.be> Organization: -= Belgacom Usenet Service =- NNTP-Posting-Host: 4c7f73e6.news.skynet.be X-Trace: 1243683736 news.skynet.be 2862 80.201.76.217:35818 X-Complaints-To: usenet-abuse@skynet.be Xref: g2news2.google.com comp.lang.ada:6115 Date: 2009-05-30T13:41:41+02:00 List-Id: Hello, I am learning controlled types features and I do not understand the following thing. With this code: ------------------------------------- Spec ------------------------------------- with audio; use audio; with Ada.Finalization; use Ada.Finalization; package audio.effect is type Delay_Line is limited private; function Make_Delay_Line (Duration: Duration_Type) return Delay_Line; private type Delay_Line is new Controlled with record Duration: Duration_Type; end record; overriding procedure Initialize(Object: in out Delay_Line); overriding procedure Adjust(Object: in out Delay_Line); overriding procedure Finalize(Object: in out Delay_Line); end audio.effect; ------------------------------------- Body ------------------------------------- with Ada.Text_IO; use Ada.Text_IO; package body audio.effect is function Make_Delay_Line(Duration: Duration_Type) return Delay_Line is D: Delay_Line; begin Put_Line("Make_Delay_Line"); return D; end Make_Delay_Line; procedure Initialize(Object: in out Delay_Line) is begin Put_Line("Initialize Delay_Line"); end; procedure Adjust(Object: in out Delay_Line) is begin Put_Line("Adjust Delay_Line"); end; procedure Finalize(Object: in out Delay_Line) is begin Put_Line("Finalize Delay_Line"); end; end audio.effect; ------------------------------------- Test ------------------------------------- with audio.effect; use audio.effect; procedure test1 is Delay1 : Delay_Line := Make_Delay_Line(Duration => 0.1); begin null; end test1; ------------------------------------- Program output ------------------------------------- Initialize Delay_Line Make_Delay_Line Adjust Delay_Line Finalize Delay_Line Finalize Delay_Line I have two "Finalize(s)" for one "Initialize". Should I call Initialize from Adjust ? How to have only one Initialize/Finalize ? Thanks to help me, Olivier.