[fpc-pascal] A better way?
Sven Barth
pascaldragon at googlemail.com
Fri Apr 15 10:51:21 CEST 2016
Am 15.04.2016 10:46 schrieb "Tony Whyman" <tony.whyman at mccallumwhyman.com>:
>
> 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.
While it works using "absolute" for a public API is rather unsafe (I'd only
use that in private methods). In those cases the "as" operator should he
used (or at least "is" plus returning an error).
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160415/0fc58c8c/attachment.html>
More information about the fpc-pascal
mailing list