[fpc-pascal] Re: Errors using Extended Class Syntax

bsquared bwcode4u at gmail.com
Sun Nov 25 02:26:37 CET 2012


On 11/24/2012 09:06 AM, Jonas Maebe wrote:
>
> On 24 Nov 2012, at 17:55, bsquared wrote:
>
>> I followed the example on the wiki page, but the compiler disallowed both of the following attempts.
>
> On which wiki page did you find this code?

The code on the wiki does conform to your helpful comments.
http://wiki.freepascal.org/extended_class_syntax

>
>> {$mode objfpc}{$H+}
>>
>> TExample1 = class
>> private
>>   const
>>     CN_CONST = 'EXAMPLE CONSTANT';
>> published
>>   property Example: string
>>     read CN_CONST;
>> end;
>>
>> Error: Unknown class field or method identifier "CN_WELCOME"
>
> Properties can only read via methods or fields, not via constants. A constant is not the same as a field. Does Delphi allow the above?
>
>> TExample2 = class
>> private
>>   fExample: string;
>>   const
>>     CN_CONST = 'EXAMPLE CONSTANT';
>> published
>>   property Example: string
>>     read fExample
>>     write fExample
>>     default CN_CONST;
>> end;
>>
>> Error: Property can't have a default value
>
> Properties that return strings cannot have a default value. Only immediate values that moreover fit in 32 bits can be used as default value, due to the format of the RTTI. See http://bugs.freepascal.org/view.php?id=19199 for more information.
>
>> Also, What is the static keyword on the class method?
>> class procedure SetSomeClassVar(const AValue: TSomeType); static;
>
> It results in the class method not getting a hidden "self" parameter, which otherwise contains the class reference on which the class method was invoked.
>
>
> Jonas_______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
Thank you for the clarifications.

-- 
Regards,
Brian




More information about the fpc-pascal mailing list