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,cfbb90c56a313e70 X-Google-Attributes: gid103376,public X-Google-Thread: 10261c,cfbb90c56a313e70 X-Google-Attributes: gid10261c,public From: Ray Blaak Subject: Re: From extended Pascals to Ada 95 guide Date: 2000/08/28 Message-ID: #1/1 X-Deja-AN: 663603634 Sender: blaak@TORUS References: <8o3s2a$9ph$1@nnrp1.deja.com> <8o4bfq$v0h$1@slb7.atl.mindspring.net> <8obv01$7hu1@news.cis.okstate.edu> <39A991F3.A8D8BED7@easystreet.com> <39AA8FFB.C9549B55@easystreet.com> X-Complaints-To: news@bctel.net X-Trace: news.bc.tac.net 967492452 209.53.149.68 (Mon, 28 Aug 2000 12:54:12 PDT) Organization: The Transcend NNTP-Posting-Date: Mon, 28 Aug 2000 12:54:12 PDT Newsgroups: comp.lang.ada,comp.lang.pascal.misc Date: 2000-08-28T00:00:00+00:00 List-Id: Al Christians writes: > If I define my own type in a Pascal program and want to save it in > one of the VCL containers, the code would look like this: > > { To Insert } AContainer.Objects[i] := Pointer(MyObject); > { To Retrieve } MyObject := TMyObject(AContainer.Objects[i]); > With Delphi, I have always found it worthwhile to make my own container classes that do the appropriate checking: type MyContainer = class public procedure Insert(atIndex : Integer; obj : MyObject); function GetAt(index : Integer) : MyObject; private flist : TList; end; where we have: procedure MyContainer.Insert(atIndex : Integer; obj : MyObject); begin flist.Items[i] := Pointer(obj); end; function MyContainer.GetAt(index : Integer) : MyObject; begin result := MyObject(flist.Items[i]); end; and then I can do: AContainer.Insert(i, MyObject); MyObject := AContainer.GetAt(i); Now I have the benefit of good typechecking. The one disadvantage of this approach is that Delphi's lack of generics can mean constructing these wrapper classes is tedious. However, the benefit outweighs the tedium, in my opinion. -- Cheers, The Rhythm is around me, The Rhythm has control. Ray Blaak The Rhythm is inside me, blaak@infomatch.com The Rhythm has my soul.