specialize, identifier not found

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

specialize, identifier not found

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.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: specialize, identifier not found

Sven Barth-2

Am 16.12.2015 16:12 schrieb "Santiago A." <[hidden email]>:
>
> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: specialize, identifier not found

Santiago A.
El 16/12/2015 a las 17:25, Sven Barth escribió:

Am 16.12.2015 16:12 schrieb "Santiago A." <[hidden email]>:
>
> 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
[hidden email]

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: specialize, identifier not found

Santiago A.
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
-- 
Saludos

Santiago A.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: specialize, identifier not found

leledumbo
Administrator
In reply to this post by Santiago A.
> {$mode Delphi}
>
> I've just tried {$mode objfpc} and compiles type declaration, (Delphi mode can't understand generics?)

Delphi mode follows Delphi generics syntax.

Reply | Threaded
Open this post in threaded view
|

Re: specialize, identifier not found

Sven Barth-2
In reply to this post by Santiago A.
On 16.12.2015 17:57, Santiago A. wrote:

> El 16/12/2015 a las 17:25, Sven Barth escribió:
>>
>> Am 16.12.2015 16:12 schrieb "Santiago A."
>> <<mailto:[hidden email]>[hidden email]>:
>> >
>> > 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.

>
> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: specialize, identifier not found

Sven Barth-2
In reply to this post by Santiago A.
On 16.12.2015 18:09, Santiago A. wrote:
> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: specialize, identifier not found

Santiago A.
In reply to this post by Sven Barth-2
El 16/12/2015 a las 21:01, Sven Barth escribió:
> 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.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: specialize, identifier not found

Sven Barth-2

Am 17.12.2015 11:18 schrieb "Santiago A." <[hidden email]>:
> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: specialize, identifier not found

Santiago A.
El 17/12/2015 a las 11:35, Sven Barth escribió:

Am 17.12.2015 11:18 schrieb "Santiago A." <[hidden email]>:
> 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
[hidden email]

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: specialize, identifier not found

Sven Barth-2

Am 17.12.2015 13:37 schrieb "Santiago A." <[hidden email]>:
>
> El 17/12/2015 a las 11:35, Sven Barth escribió:
>>
>> Am 17.12.2015 11:18 schrieb "Santiago A." <[hidden email]>:
>> > 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)

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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal