Recent

Author Topic: lang enhance record field tags  (Read 656 times)


MarkMLl

  • Hero Member
  • *****
  • Posts: 5191
Re: lang enhance record field tags
« Reply #1 on: July 31, 2022, 08:21:35 pm »
In what useful way does that differ from what's already supported (LRM 4.4)?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 4562
  • Compiler Developer
Re: lang enhance record field tags
« Reply #2 on: August 01, 2022, 01:18:21 pm »
https://www.golangprograms.com/use-field-tags-in-the-definition-of-struct-type-in-go-programming-language.html

Once extended RTTI is supported, the current attribute support (which only works for types) will be extended to fields as well:

Code: Pascal  [Select][+][-]
  1. type
  2.   // assumes that there is a JSONAttribute type that descends from TCustomAttribute
  3.   TEmployee = record
  4.     [JSON('firstname')]
  5.     FirstName: String;
  6.     [JSON('lastname')]
  7.     LastName: String;
  8.     [JSON('city')]
  9.     City: String;
  10.   end;

They can then be accessed using Attributes property of the corresponding types in unit Rtti.
« Last Edit: August 02, 2022, 07:37:18 am by PascalDragon »

440bx

  • Hero Member
  • *****
  • Posts: 3027
Re: lang enhance record field tags
« Reply #3 on: August 01, 2022, 07:39:23 pm »
I presume the second field is named "LastName" instead of FirstName (otherwise the compiler would rightfully complain about a duplicate identifier.)
« Last Edit: August 02, 2022, 06:23:00 pm by 440bx »
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4562
  • Compiler Developer
Re: lang enhance record field tags
« Reply #4 on: August 02, 2022, 07:38:57 am »
I presume the second field is named "LastName" instead of FirstName (otherwise the compiler would rightfully complain about a duplicate identifier.)

Yes, obviously. :-[ Thank you for the correction (I fixed it now)

 

TinyPortal © 2005-2018