Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2015-04

Generic List in Advanded record does not compile with -MobjFPC, works with -MDelphi (perhaps related to Generics.Collections that I am using)

11 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Ring

I am not sure if this is a problem of the Generics.Collections unit I am using (https://github.com/dathox/generics.collections) as this unit is always compiled with -Mdelphi or if this is an issue with fpc's parser.

The following snippet compiles fine in delphi mode, but does not compile in ObjectFPC Mode:

type
   TSpecialFunctionBits = record
     name: String;
     Position: longWord;
     Mask: longWord;
     notMask: longWord;
     Length: longWord;
     constructor create(theName: String; thePosition, theMask,
theLength: longWord);
   end;

Error is:

Fatal: Syntax error, ";" expected but "<" found

I saw this error with trunk fpc.

Michael

Reply by email

Sven Barth
to Michael Ring
Michael Ring wrote 23 lines
I am not sure if this is a problem of the Generics.Collections unit I am using (https://github.com/dathox/generics.collections) as this unit is always compiled with -Mdelphi or if this is an issue with fpc's parser. The following snippet compiles fine in delphi mode, but does not compile in ObjectFPC Mode: type TSpecialFunctionBits = record name: String; Position: longWord; Mask: longWord; notMask: longWord; Length: longWord; constructor create(theName: String; thePosition, theMask, theLength: longWord); end; Error is: Fatal: Syntax error, ";" expected but "<" found I saw this error with trunk fpc.

Are you sure that's the correct location? I don't see a "<" anywhere there. Can it be that you are missing a "specialize" where you're specializing the generic? Also note that ObjFPC does not support inline specializations (yet), specializations must be done in "type" sections.

Regards,
Sven

Reply by email

Michael Ring
to Sven Barth

Argh, soory, cut & waste error, this is the correct thing:

   TSpecialFunctionRegister = record
     name: String;
     device: String;
     address: longWord;
     bits: TList<TSpecialFunctionBits>;
     constructor create(theName: String; theAddress: longWord);
   end;
Sven Barth wrote 37 lines
On 27.04.2015 20:19, Michael Ring wrote: > I am not sure if this is a problem of the Generics.Collections unit I am > using (https://github.com/dathox/generics.collections) as this unit is > always compiled with -Mdelphi or if this is an issue with fpc's parser. > > The following snippet compiles fine in delphi mode, but does not compile > in ObjectFPC Mode: > > type > TSpecialFunctionBits = record > name: String; > Position: longWord; > Mask: longWord; > notMask: longWord; > Length: longWord; > constructor create(theName: String; thePosition, theMask, > theLength: longWord); > end; > > Error is: > > Fatal: Syntax error, ";" expected but "<" found > > I saw this error with trunk fpc. Are you sure that's the correct location? I don't see a "<" anywhere there. Can it be that you are missing a "specialize" where you're specializing the generic? Also note that ObjFPC does not support inline specializations (yet), specializations must be done in "type" sections. Regards, Sven _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Sven Barth
to Michael Ring
Michael Ring wrote 10 lines
Argh, soory, cut & waste error, this is the correct thing: TSpecialFunctionRegister = record name: String; device: String; address: longWord; bits: TList<TSpecialFunctionBits>; constructor create(theName: String; theAddress: longWord); end;

As I expected. Try this:

=== code begin ===

TSpecialFunctionRegister = record
public type
   TSpecialFunctionBitsList = specialize TList<TSpecialFunctionBits>
   // alternatively you could declare that outside of the record as well
if you need it more often
public
   name: String;
   device: String;
   address: LongWord;
   bits: TSpecialFunctionBitsList;
   constructor Create(theName: String; theAddress: LongWord);
end;

=== code end ===

Regards,
Sven

Reply by email

Michael Ring
to Sven Barth

Did not work, now I get

Fatal: Syntax error, ";" expected but "identifier PUBLIC" found

I did a cut & paste of your code into my code

Michael

Sven Barth wrote 36 lines
On 27.04.2015 20:31, Michael Ring wrote: > Argh, soory, cut & waste error, this is the correct thing: > > TSpecialFunctionRegister = record > name: String; > device: String; > address: longWord; > bits: TList<TSpecialFunctionBits>; > constructor create(theName: String; theAddress: longWord); > end; > As I expected. Try this: === code begin === TSpecialFunctionRegister = record public type TSpecialFunctionBitsList = specialize TList<TSpecialFunctionBits> // alternatively you could declare that outside of the record as well if you need it more often public name: String; device: String; address: LongWord; bits: TSpecialFunctionBitsList; constructor Create(theName: String; theAddress: LongWord); end; === code end === Regards, Sven _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Sven Barth
to Michael Ring
Michael Ring wrote 5 lines
Did not work, now I get Fatal: Syntax error, ";" expected but "identifier PUBLIC" found I did a cut & paste of your code into my code

Do you have {$modeswitch advancedrecords} enabled? I thought you already have that, because of the "constructor" (without that modeswitch constructors/methods wouldn't work either).

Regards,
Sven

Reply by email

David Copeland
to Michael Ring: Did not work, now I get Fatal: Syntax error, ";" expected but "identifier PUBLIC" found I…

Maybe try adding a semi-colon at the location marked below.

Michael Ring wrote 24 lines
Did not work, now I get Fatal: Syntax error, ";" expected but "identifier PUBLIC" found I did a cut & paste of your code into my code Michael === code begin === > > TSpecialFunctionRegister = record > public type > TSpecialFunctionBitsList = specialize TList<TSpecialFunctionBits> ; > // <- semi-colon added here > // alternatively you could declare that outside of the record as > well if you need it more often > public > name: String; > device: String; > address: LongWord; > bits: TSpecialFunctionBitsList; > constructor Create(theName: String; theAddress: LongWord); > end; > > === code end ===

Reply by email

Jeppe Johansen
to Michael Ring: Did not work, now I get Fatal: Syntax error, ";" expected but "identifier PUBLIC" found I…

There's a missing ; after the specialization

Michael Ring wrote 50 lines
Did not work, now I get Fatal: Syntax error, ";" expected but "identifier PUBLIC" found I did a cut & paste of your code into my code Michael Am 27.04.15 um 21:19 schrieb Sven Barth: > On 27.04.2015 20:31, Michael Ring wrote: >> Argh, soory, cut & waste error, this is the correct thing: >> >> TSpecialFunctionRegister = record >> name: String; >> device: String; >> address: longWord; >> bits: TList<TSpecialFunctionBits>; >> constructor create(theName: String; theAddress: longWord); >> end; >> > > As I expected. Try this: > > === code begin === > > TSpecialFunctionRegister = record > public type > TSpecialFunctionBitsList = specialize TList<TSpecialFunctionBits> > // alternatively you could declare that outside of the record as > well if you need it more often > public > name: String; > device: String; > address: LongWord; > bits: TSpecialFunctionBitsList; > constructor Create(theName: String; theAddress: LongWord); > end; > > === code end === > > Regards, > Sven > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Michael Ring
to Jeppe Johansen

I now officially feel stupid, this now works with the ; in place, I could have sworn that I have tried this......

But two lines deeper I end up with a new problem now:

   TSpecialFunctionRegisterComparer =
class(TComparer<TSpecialFunctionRegister>)
     function Compare(constref Left, Right: TSpecialFunctionRegister):
Integer; override;
   end;

Error: class type expected, but got "TComparer"
Fatal: class type expected, but got "TComparer"

Is this a similar problem?

If yes then I guess I will need to stay with -Mdelphi the specialize syntax is not availabe in delphi mode (identifier not found "specialize") and the generics library where TComparer comes from explicitly sets delphi mode.

Michael

Jeppe Johansen wrote 57 lines
There's a missing ; after the specialization , On 04/27/2015 09:46 PM, Michael Ring wrote: > Did not work, now I get > > Fatal: Syntax error, ";" expected but "identifier PUBLIC" found > > I did a cut & paste of your code into my code > > Michael > > Am 27.04.15 um 21:19 schrieb Sven Barth: >> On 27.04.2015 20:31, Michael Ring wrote: >>> Argh, soory, cut & waste error, this is the correct thing: >>> >>> TSpecialFunctionRegister = record >>> name: String; >>> device: String; >>> address: longWord; >>> bits: TList<TSpecialFunctionBits>; >>> constructor create(theName: String; theAddress: longWord); >>> end; >>> >> >> As I expected. Try this: >> >> === code begin === >> >> TSpecialFunctionRegister = record >> public type >> TSpecialFunctionBitsList = specialize TList<TSpecialFunctionBits> >> // alternatively you could declare that outside of the record as >> well if you need it more often >> public >> name: String; >> device: String; >> address: LongWord; >> bits: TSpecialFunctionBitsList; >> constructor Create(theName: String; theAddress: LongWord); >> end; >> >> === code end === >> >> Regards, >> Sven >> _______________________________________________ >> fpc-devel maillist - >> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Sven Barth
to Michael Ring
"Michael Ring" wrote
I now officially feel stupid, this now works with the ; in place, I could

have sworn that I have tried this......

But two lines deeper I end up with a new problem now: TSpecialFunctionRegisterComparer =

class(TComparer<TSpecialFunctionRegister>)

function Compare(constref Left, Right: TSpecialFunctionRegister):
Integer; override;
Show quoted text 8 lines
end; Error: class type expected, but got "TComparer" Fatal: class type expected, but got "TComparer" Is this a similar problem? If yes then I guess I will need to stay with -Mdelphi the specialize

syntax is not availabe in delphi mode (identifier not found "specialize") and the generics library where TComparer comes from explicitly sets delphi mode.

In mode ObjFPC you must use "specialize" when you want to specialize a class, this includes the declaration of the class parent. Also mixing generics from different modes makes no difference, the compiler supports that.

Regards,
Sven

Reply by email