In message 199912292231.OAA17912@ego.mind.net "Russ Whitaker" writes:
Hi David James wrote:
Subject: Bug? Variants don't overlay when they contain strings
Should the different variants in a variant record overlay in the same memory?
You have more than an overlay problem. In standard pascal you expect ic[ 1 ] to align with the first character position of s and thus one character to the left is the length of s. Thus ic[0] is the length of s.
In extended pascal there is 8 bytes to the left of the first charactor position makingt ic[ 0 ] useless So you end up leaving s out of Trec but what you can do is index s like an array[ 1..CAPACITY] and use Setlength when you need to.
In this artificially simple example, yes; however my real-life example is much more complicated, some of the variants are themselves records which contain strings, the aim was to get a byte array which was overlaid on all the variants (which is then sent over a network connection to another machine where an identical variant record receives bytes into the byte array and then uses the appropriate variant). I can work around the problem (by throwing away the variant record, keeping the individual variants and copying them to the byte array as needed).
My question is still: should variants overlay in memory? I think I understand why they don't (I assume it's so that the string capacities do not get smashed by the other variants), but it's a nasty feature that could do to be highlighted in the documentation (maybe it is, but I haven't found it).