[fpc-pascal] Re: [fpc-devel] Illegal type conversion errors in FPC 2.5.1

Juha Manninen juha.manninen at phnet.fi
Mon Nov 23 13:11:16 CET 2009


On maanantai, 23. marraskuuta 2009 00:13:20 Jonas Maebe wrote:
> On 22 Nov 2009, at 23:06, Jonas Maebe wrote:
> > the size of sets in Delphi and TP mode has been made Delphi/TP compatible
> > by default, i.o.w.: {$packsets 1}
> 
> Sorry, that should read {$packset 1}. And the remedy is to either change
>  the typecast, or (and this is backward compatible) add {$packset 4} to the
>  source.

Thanks. It compiles and works now.
In the latest Delphi VirtualTreeView version the typecast is changed to Byte 
or Word depending on the element count in a set.
I decided to do the same thing. Then I realized the code doesn't work with FPC 
2.2.4, so I added {$packset 1} or {$packset 2} directives.
{$packset 1} if elementcount < 9.
{$packset 2} if 8 < elementcount < 17.
And I changed the typecasts accordingly to Byte or Word.

For example:

  // Options per column.
  TVTColumnOption = (
    coAllowClick,
    coDraggable,
    coEnabled,
    coParentBidiMode,
    coParentColor,
    coResizable,
    coShowDropMark,
    coVisible,
    coAutoSpring,
    coFixed,
    coSmartResize,
    coAllowFocus,
    coDisableAnimatedResize,
    coWrapCaption,
    coUseCaptionAlignment
  );
  {$packset 2}
  TVTColumnOptions = set of TVTColumnOption;
  {$packset default}

Fine. Then I thought, what if someone will add more element into the set?
2 more element makes already 17 here.
I tested this "overflow of set space" situation with this:

  {$packset 1}
  TVTColumnOptions = set of TVTColumnOption;
  {$packset default}

The compiler should give an error but it doesn't! The code will not work as 
intended (I guess).

What happens if (without $packset directives) a set has 17 elements?
Does it use 3 or 4 bytes? What if there are > 32 elements?

The casting here is used for streaming data, with Stream WriteBuffer and 
ReadBuffer.
Is there any better way of doing this than casting to Byte, Word or LongWord 
and counting the elements?


Juha Manninen



More information about the fpc-pascal mailing list