Recent

Author Topic: Error: This kind of property cannot be published  (Read 1041 times)

maicounir

  • Newbie
  • Posts: 3
Error: This kind of property cannot be published
« on: March 23, 2023, 07:26:49 pm »
Hello! I have the following code below:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode Delphi}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, nullable, Generics.Collections;
  9.  
  10. type
  11.   TNullableInteger = TNullable<Integer>;
  12.   TNullableDouble = TNullable<Double>;
  13.   TNullableString = TNullable<String>;
  14.  
  15.   { TColumn }
  16.  
  17.   TColumn = class(TCustomAttribute)
  18.   private
  19.     FName: String;
  20.   public
  21.     constructor Create(aName: String);
  22.  
  23.     property Name: String read FName write FName;
  24.   end;
  25.  
  26.  
  27.   TMyClass = class
  28.   private
  29.     FID: TNullableInteger;
  30.   published
  31.     [TColumn('ID')]
  32.     property ID: TNullableInteger read FID write FID;
  33.   end;
  34.  
  35. implementation
  36.  
  37. { TColumn }
  38.  
  39. constructor TColumn.Create(aName: String);
  40. begin
  41.   FName := aName;
  42. end;
  43.  
  44. end.  

The compiler returns me the following error:
Quote
unit1.pas(32,35) Error: This kind of property cannot be published

Is there any way to work with Nullable and CustomAttributes together? Because nullable works only with public field and TCustomAttribute only with published field.

Lazarus 2.3.0 (rev 4aeb1eb0ff) FPC 3.3.1 x86_64-win64-win32/win64
« Last Edit: March 23, 2023, 07:34:21 pm by maicounir »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Error: This kind of property cannot be published
« Reply #1 on: March 23, 2023, 09:40:21 pm »
Is there any way to work with Nullable and CustomAttributes together? Because nullable works only with public field and TCustomAttribute only with published field.

Currently not. Once Extended RTTI is enabled you can also use custom attributes with public properties.

maicounir

  • Newbie
  • Posts: 3
Re: Error: This kind of property cannot be published
« Reply #2 on: March 23, 2023, 10:20:31 pm »
Is there any way to test or activate RTTI Extended?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Error: This kind of property cannot be published
« Reply #3 on: March 24, 2023, 10:20:13 pm »
Is there any way to test or activate RTTI Extended?

No, because it isn't available yet.

maicounir

  • Newbie
  • Posts: 3
Re: Error: This kind of property cannot be published
« Reply #4 on: March 25, 2023, 02:19:59 pm »
Is there any way to test or activate RTTI Extended?

No, because it isn't available yet.

Thanks for the explanation, I will implement otherwise until this feature is available.

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Error: This kind of property cannot be published
« Reply #5 on: March 25, 2023, 02:49:13 pm »
Not to be rude but, I been around the coding seen for many years and I cannot seem to understand why some would have such a craving for Generics when I've found very little use for it.

 I like to keep things efficient in code use, I guess.
The only true wisdom is knowing you know nothing

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Error: This kind of property cannot be published
« Reply #6 on: March 25, 2023, 04:21:07 pm »
Not to be rude but, I been around the coding seen for many years and I cannot seem to understand why some would have such a craving for Generics when I've found very little use for it.

 I like to keep things efficient in code use, I guess.

Generics allow the reuse of shared Pascal code for different types and as they're done at compile time they'll result in more efficient code than types that are implemented as general ones (e.g. Classes.TObjectList vs. Generics.Collections.TObjectList<>).

 

TinyPortal © 2005-2018