[fpc-pascal] A better way?

Tony Whyman tony.whyman at mccallumwhyman.com
Fri Apr 15 10:46:00 CEST 2016


Ryan,

If you want to get rid of (ugly) typecasts then maybe you should 
investigate the "absolute" keyword. You get a lot of examples in the 
LCL. For example, here's one I chose at random:

function TGtk2WidgetSet.RawImage_CreateBitmaps(const ARawImage: 
TRawImage; out
   ABitmap, AMask: HBitmap; ASkipMask: boolean): boolean;
var
   GdiObject: PGDIObject absolute ABitmap;
   GdiMaskObject: PGDIObject absolute AMask;
   Desc: TRawImageDescription absolute ARawImage.Description;
....


You could describe it as typecast done in the var clause of a method. 
The right hand identifier is not restricted to function parameters.

Regards

Tony Whyman
MWA

On 15/04/16 07:15, Ryan Joseph wrote:
> I’ve cleaned up some code by declaring uses in the implementation and using generic untyped variables like TObject for parameters. This compiles but I’m left with lots of ugly type casting in the implementation because the parameters for methods are untyped. Yes it works but I feel like the compiler could be helping more.
>
>
>




More information about the fpc-pascal mailing list