Path: utzoo!attcan!uunet!cs.utexas.edu!rutgers!psuvax1!xavier!jackiw From: jackiw@cs.swarthmore.edu (Nick Jackiw) Newsgroups: comp.sys.mac.programmer Subject: Re: Using a handle to get data: How? Message-ID: Date: 9 Jul 90 13:57:36 GMT References: <1990Jul8.171009.1@mel.cipl.uiowa> Sender: news@xavier.swarthmore.edu (Usenet News) Reply-To: jackiw@cs.swarthmore.edu (Nick Jackiw) Organization: Visual Geometry Project, Swarthmore College, PA Lines: 39 wolf@mel.cipl.uiowa writes: > Basically what I want to know is how to use a handle to get a value of a > certain byte at a specified offset from the handle. > > If someone could enlighten me on this I would be very appreciative. I am will > take responses in pascal (I am using turbo at the time). > If Turbo Pascal supports packed arrays, try this: function ByteAtOffset(myHandle:Handle,myOffset:longint):Byte; type ByteArray= packed array [0..3] of byte; pByteArray=^ByteArray; hByteArray=^pByteArray; begin ByteAtOffset:=hByteArray(myHandle)^^[myOffset] end; This is known as "coercing" a data type: Handle normally points to a pointer which points to a byte; we coerce it to point indirectly to an array of bytes. We need "packed array" because otherwise the compiler may allocate the array of bytes internally as an array of words, with the byte value occupying only half the storage space of a given element. We can define the array as only [0..3] and yet access any element (e. g. [1000]) only if there is no implicit range-checking in the compiler; if there is, we must explicitly declare a maximum size ([0..16383], for instance), which is not quite as good, in that it prevents us from accessing bytes #16384 and up. Hope this helps. -- --- jackiw@cs.swarthmore.edu | Smoggo: Can you prevent the detonation of jackiw@swarthmr.bitnet | the thermonuclear device? Applelink: D3717 | Jimbo: No ... I cannot.