[fpc-pascal] fcl-passrc errors

Ryan Joseph genericptr at gmail.com
Sun Oct 13 16:21:53 CEST 2019



> 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;


Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list