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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,324453f076c10aeb X-Google-Attributes: gid103376,public From: LeakyStain Subject: Re: Exposing agreggate members of a class Date: 1998/12/31 Message-ID: <368B738E.23BC574@erols.com>#1/1 X-Deja-AN: 427439454 Content-Transfer-Encoding: 7bit References: <76cd39$21c8$1@news.gate.net> Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@rcn.com X-Trace: 2doEUN9Uq1ZAUtZPq7OFuGelxLodRB5z5gtEt0vCZjs= Mime-Version: 1.0 NNTP-Posting-Date: 31 Dec 1998 12:52:39 GMT Newsgroups: comp.lang.ada Date: 1998-12-31T12:52:39+00:00 List-Id: David Botton wrote: > > Given: > > with GCanvas_Package; use GCanvas_Package; > > type GWindow_Object is tagged with private; > type GWindow_Pointer is access all GWindow_Object; > > private: > > type GWindow_Object is tagged > record > Canvas : GCanvas_Object; > end record; > > What is the cleanest way to give access to the Canvas by reference in a way > that will not require Unchecked Programming Depends on how much "acess" the clients need. If they can destroy Canvas, then it should not be private. Windex (http://www.erols.com/leakstan/stephe/index.html) solves a similar problem; shared access to a Win32 Device Context. The approach I take is to declare the basic Device Context operations to take a class-wide object parameter: package Windex.Graphics_Devices is type Handle_Type is new Root_Handle_Type with private; procedure BitBlt (Dest_Image : in Handle_Type'class; ); ... other operations end package Windex.Graphics_Devices; Root_Handle_Type is derived from Ada.Finalization.Limited_Controlled. Then, in a child package, declare a type that takes a Windex.Windows object as a discriminant: package Windex.Graphics_Devices.Windows is type Handle_Type (Owner : access Windex.Windows.Handle_Type'class) is new Windex.Graphics_Devices.Handle_Type with null record; -- Handle_Type can be used with all Windex.Graphics_Devices operations. procedure Initialize (Handle : in out Handle_Type); -- Get the device context for Window. This locks the window for drawing; -- after drawing, Handle must be finalized to allow normal Window -- painting. procedure Finalize (Handle : in out Handle_Type); -- Release window device context. end Windex.Graphics_Devices.Windows; This allows any Windex.Windows object to gain temporary exclusive access to the Device_Context. All Paint operations in a window procedure use a Windex.Graphics_Devices.Windows object to gain lock the Device_Context for drawing. Hope this helps. -- Stephe