[fpc-pascal] fcl-passrc errors

Sven Barth pascaldragon at googlemail.com
Sun Oct 13 17:11:35 CEST 2019


Ryan Joseph <genericptr at gmail.com> schrieb am So., 13. Okt. 2019, 16:22:

>
>
> > On Oct 13, 2019, at 5:58 AM, Sven Barth via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> >
> >> Delphi does not allow it:
> >>
> >> [dcc32 Error] Project1.dpr(18): E1019 For loop control variable must be
> simple local variable
> >>
> >> I don't think this should be allowed, either.
> >
> > Same.
>
> Why not?
>
> I just had this problem on 9/26, search for “for-in loop cast”. What if I
> have a list of TObjects I want to iterate? I know TMyClass is safe to use
> but the compiler complains so I override it with a typecast. If you take
> that away I’ll have to do tons of casting outside of the loop.
>
> var
>   arr: specialize TFPGObjectList<TObject>;
>   obj: TMyClass;
> begin
>   arr := specialize TFPGObjectList<TObject>.Create;
>   arr.Add(TObject.Create);
>   // Incompatible types: got "TObject" expected "TMyClass"
>   for obj in arr do
>     begin
>     end;
>

Then specialize the list with the correct type.

This issue *will* be fixed and is not up to discussion.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20191013/27470e05/attachment.html>


More information about the fpc-pascal mailing list