Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!clyde.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!julius.cs.uiuc.edu!ux1.cso.uiuc.edu!uxa.cso.uiuc.edu!dslg0849 From: dslg0849@uxa.cso.uiuc.edu (Daniel S. Lewart) Newsgroups: comp.lang.pascal Subject: Re: Help: How can I implement a record with variable width Message-ID: <1991Jan7.004145.12324@ux1.cso.uiuc.edu> Date: 7 Jan 91 00:41:45 GMT References: <29636@shamash.cdc.com> Sender: news@ux1.cso.uiuc.edu (News) Organization: University of Illinois at Urbana Lines: 39 mpe@shamash.cdc.com (Mike Ebsen) writes: > I would like to implement a variable record length record using Turbo > pascal 5.5. > > type > element_type = record > number_of_items : word; > items : array [1..number_of_items] of real; > end; > > I've seen variant record structures before, but nothing which allows the > size of an array to modulate as a function of a variable contained within > the record. ------------------------------------------------------------------------------- type TRealArray = array[1..10000] of Real; element_type = record number_of_items : word; ItemsPtr : ^TRealArray; end; var Element: element_type; Begin { ... Set Element.number_of_items ... } with Element do GetMem( ItemsPtr, SizeOf(Real)*number_of_items ); { ... } with Element do FreeMem( ItemsPtr, SizeOf(Real)*number_of_items ); { ... } End. ------------------------------------------------------------------------------- Your problem calls for dynamic arrays, not variant records. The above code does what you want. Daniel Lewart d-lewart@uiuc.edu