[fpc-pascal] Range checks

Dmitry Boyarintsev skalogryz.lists at gmail.com
Sat Jan 27 18:51:49 CET 2018


On Sat, Jan 27, 2018 at 12:30 PM, C Western <l at c-m-w.me.uk> wrote:
>
> The actual code that triggered my interest was:
>
> procedure LCLViewExtension.lclSetEnabled(AEnabled: Boolean);
> var
>   ns : NSArray;
>   i  : integer;
>   obj : NSObject;
> begin
>   ns := subviews;
>   for i := 0 to ns.count - 1 do
>   begin
>     obj := NSObject(ns.objectAtIndex( i ));
>     ... process obj ...
>   end;
> end;
>
>
> Given how common the above bit of code is likely to be, I can't see any
> way of fixing this without some work in the compiler.


imho, bad approach to adjust compiler for not safe code.
However, getting a compiler warning would be nice.

Some time ago, the compiler has been extended with for-in syntax:

var
  SubView : NSView;
begin
  for SubView in ns.subviews do
  begin
    .. process obj ...
  end

thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180127/aa62c25f/attachment.html>


More information about the fpc-pascal mailing list