Sign in Join

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

Mailing lists / fpc-pascal / 2015-12

specialize, identifier not found

11 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Santiago A.
Type
 TRegAlias=record
    ...
 end;
 TArrayAlias=specialize TArray<TRegAlias>; // <==== Error here
defconexion.pas(71,14) Error: Identifier not found "specialize"
defconexion.pas(71,25) Error: Error in type definition
defconexion.pas(71,25) Fatal: Syntax error, ";" expected but "identifier
TARRAY" found

Why this error?
Why does the compiler try to look for a Identifier "specialize" instead of interpreting it as a reserved word?

Saludos Santiago A.
Sven Barth
to Santiago A.
"Santiago A." wrote 17 lines
Type TRegAlias=record ... end; TArrayAlias=specialize TArray<TRegAlias>; // <==== Error here defconexion.pas(71,14) Error: Identifier not found "specialize" defconexion.pas(71,25) Error: Error in type definition defconexion.pas(71,25) Fatal: Syntax error, ";" expected but "identifier TARRAY" found Why this error? Why does the compiler try to look for a Identifier "specialize" instead of interpreting it as a reserved word?

Which FPC version? Which language mode?

Regards,
Sven

Santiago A.
to Sven Barth
Sven Barth wrote 24 lines
Am 16.12.2015 16:12 schrieb "Santiago A." < >: > > Type > TRegAlias=record > AliasName:string > ... > end; > > TArrayAlias=specialize TArray<TRegAlias>; // <==== Error here > > defconexion.pas(71,14) Error: Identifier not found "specialize" > defconexion.pas(71,25) Error: Error in type definition > defconexion.pas(71,25) Fatal: Syntax error, ";" expected but "identifier > TARRAY" found > > > Why this error? > Why does the compiler try to look for a Identifier "specialize" instead > of interpreting it as a reserved word? Which FPC version? Which language mode?
{$mode Delphi}

I've just tried {$mode objfpc} and compiles type declaration, (Delphi mode can't understand generics?)

But now I have another problem, when I use the variable, I get "Argument can't be assigned to"

var
  arrayAlias:TArrayAlias;
  aliasList:TStringList;
  ...
begin
...
  arrayAlias[i].AliasName:=aliasList[i]; //<==== Error here

Where TArrayAlias=TArray<TRegAlias>, and TArray<_T> is an object, not a class.
And it has a property

      property item[index:Integer]:_T read getItem write setItem; default;

So, it has the getter and the setter.

Doesn't objfpc mode accept default indexed properties?

Saludos Santi
Santiago A.
to Santiago A.
Santiago A. wrote
Which FPC version? Which language mode?

Sorry, I have forgotten version.

{$mode Delphi}
FPC 2.6.4
Same result on Win XP 32bits and Linux Gtk 64bits

Saludos Santiago A.
Sven Barth
to Santiago A.: {$mode Delphi} I've just tried {$mode objfpc} and compiles type declaration, (Delphi mode…
Santiago A. wrote 29 lines
El 16/12/2015 a las 17:25, Sven Barth escribió: > > Am 16.12.2015 16:12 schrieb "Santiago A." > : > > > > Type > > TRegAlias=record > > AliasName:string > > ... > > end; > > > > TArrayAlias=specialize TArray<TRegAlias>; // <==== Error here > > > > defconexion.pas(71,14) Error: Identifier not found "specialize" > > defconexion.pas(71,25) Error: Error in type definition > > defconexion.pas(71,25) Fatal: Syntax error, ";" expected but "identifier > > TARRAY" found > > > > > > Why this error? > > Why does the compiler try to look for a Identifier "specialize" instead > > of interpreting it as a reserved word? > > Which FPC version? Which language mode? > {$mode Delphi} I've just tried {$mode objfpc} and compiles type declaration, (Delphi mode can't understand generics?)

Mode Delphi follows Delphi's syntax, thus no "generic" and "specialize" keywords.

Show quoted text 21 lines
But now I have another problem, when I use the variable, I get "Argument can't be assigned to" var arrayAlias:TArrayAlias; aliasList:TStringList; ... begin ... arrayAlias[i].AliasName:=aliasList[i]; //<==== Error here Where TArrayAlias=TArray<TRegAlias>, and TArray<_T> is an object, not a class. And it has a property property item[index:Integer]:_T read getItem write setItem; default; So, it has the getter and the setter. Doesn't objfpc mode accept default indexed properties?

The problem isn't default indexed properties. I guess your TRegAlias is a record, thus it will be victim of this:
http://wiki.freepascal.org/User_Changes_2.4.0#Treating_direct-mapped_properties_as_regular_fields

Regards,
Sven

Sven Barth
to Santiago A.: Sorry, I have forgotten version. {$mode Delphi} FPC 2.6.4 Same result on Win XP 32bits…
Santiago A. wrote 7 lines
El 16/12/2015 a las 17:57, Santiago A. escribió: > Which FPC version? Which language mode? Sorry, I have forgotten version. {$mode Delphi} FPC 2.6.4 Same result on Win XP 32bits and Linux Gtk 64bits

I'd suggest you to switch to FPC 3.0.0. While not related to your specific problems there were many improvements regarding generics since 2.6.4.

Regards,
Sven

Santiago A.
to Sven Barth: Mode Delphi follows Delphi's syntax, thus no "generic" and "specialize" keywords. The…
Sven Barth wrote
Mode Delphi follows Delphi's syntax, thus no "generic" and "specialize" keywords.

Yes, you are right. I was just looking the objfpc syntax.

The problem isn't default indexed properties. I guess your TRegAlias is a record, thus it will be victim of this: http://wiki.freepascal.org/User_Changes_2.4.0#Treating_direct-mapped_properties_as_regular_fields

Yes, it looks like that's the problem.

TReg=record
  regField_1:string;
  regField_1:string;
end;
TMyObject=object
  ...
  property Reg:TReg read getReg write setReg;
end;
Var myObject:TMyObject;

I Can't do this:

myObject.reg.regField_1:='A';
myObject.reg.regField_2:='B';

I have to do this:

var auxReg:TReg;
...
auxReg:=myObject.reg;
auxReg.regField_1:='A';
auxReg.regField_2:='B';
myObject.reg:=auxReg;

I can live with no passing them as var parameters, but I thing it is a little cumbersome for setting fields. I will try using pointers.

Thanks, it was driving me mad.

Saludos Santiago A.
Sven Barth
to Santiago A.
"Santiago A." wrote
I can live with no passing them as var parameters, but I thing it is a little cumbersome for setting fields. I will try using pointers.

What do you mean with var-parameters?

Regards,
Sven

Santiago A.
to Sven Barth
Sven Barth wrote 8 lines
Am 17.12.2015 11:18 schrieb "Santiago A." < >: > I can live with no passing them as var parameters, but I thing it is a > little cumbersome for setting fields. I will try using pointers. What do you mean with var-parameters?

I can't use the field as actual parameter of function with a var parameter:

function foo(var n:integer);
begin
 n:=n+1;
end;

foo(myObject.Reg.fieldReg)

Saludos Santi
Sven Barth
to Santiago A.
"Santiago A." wrote 11 lines
El 17/12/2015 a las 11:35, Sven Barth escribió: > > Am 17.12.2015 11:18 schrieb "Santiago A." : > > I can live with no passing them as var parameters, but I thing it is a > > little cumbersome for setting fields. I will try using pointers. > > What do you mean with var-parameters? I can't use the field as actual parameter of function with a var

parameter:

Show quoted text 7 lines
function foo(var n:integer); begin n:=n+1; end; foo(myObject.Reg.fieldReg)

That has an analogous reason as for the other problem. See here: http://wiki.freepascal.org/User_Changes_2.6.0#Taking_the_address_of_fields_of_record_properties

Regards,
Sven