Using variant parts in records makes a lot of things easier. For example, I wrote a color structure that looks like this:
[pascal] TMyColor = record
case boolean of
false: (color: cardinal);
true: (rgba: packed array[1..4] of byte);
end;[/pascal]
It works great! Any changes made to the one interpretation get applied automatically to the other, because they're mapped to the same memory. But trying to set up a bitfield for easy bitwise operations... doesn't seem to work.
[pascal] TBitfield16 = record
case boolean of
false: (num: word);
true: (bits: packed array[1..16] of boolean);
end;[/pascal]
In this one, changes made to the one value don't seem to affect the other one. Anyone know why, and how I can fix it?