Recent

Author Topic: RTTI and record  (Read 451 times)

nomorelogic

  • Full Member
  • ***
  • Posts: 127
RTTI and record
« on: May 29, 2020, 05:12:55 pm »
hi all

reading this post I can see RTTI on record is work-in-progress
https://forum.lazarus.freepascal.org/index.php/topic,47862.msg343733.html

is there a way to get a field value from a record like GetStrProp?
Function  GetStrProp(Instance: TObject; const PropName: string): string;


thanks
nomorelogic

jamie

  • Hero Member
  • *****
  • Posts: 3121
Re: RTTI and record
« Reply #1 on: May 29, 2020, 06:35:16 pm »
why can't you just create a class with your Properties in it in the published section ? you would just about end up with the same..

 The same can be said about the old Object too where as those can be use non dynamically unless classes and behave like a record if you wish..

The only true wisdom is knowing you know nothing

nomorelogic

  • Full Member
  • ***
  • Posts: 127
Re: RTTI and record
« Reply #2 on: May 29, 2020, 07:42:25 pm »
hi
I need nullable type thus I need records.
RTTI is needed to serialize from/to JSON


Thaddy

  • Hero Member
  • *****
  • Posts: 10199
Re: RTTI and record
« Reply #3 on: May 29, 2020, 07:46:57 pm »
Maciej already did nullable types in mORMot.
I am more like donkey than shrek

PascalDragon

  • Hero Member
  • *****
  • Posts: 1742
  • Compiler Developer
Re: RTTI and record
« Reply #4 on: May 30, 2020, 11:07:41 am »
reading this post I can see RTTI on record is work-in-progress
https://forum.lazarus.freepascal.org/index.php/topic,47862.msg343733.html

is there a way to get a field value from a record like GetStrProp?
Function  GetStrProp(Instance: TObject; const PropName: string): string;

There is currently no mapping from field names to record field offsets. That would be part of the Extended RTTI which is still work-in-progress.

nomorelogic

  • Full Member
  • ***
  • Posts: 127
Re: RTTI and record
« Reply #5 on: May 30, 2020, 12:05:07 pm »
@Thaddy
thanks for your suggestion
looked in mORMot, i see nullable are variants but I prefer native types for data

@PascalDragon
thanks for the info

eljo

  • Sr. Member
  • ****
  • Posts: 408
Re: RTTI and record
« Reply #6 on: May 30, 2020, 12:25:32 pm »
@Thaddy
thanks for your suggestion
looked in mORMot, i see nullable are variants but I prefer native types for data

@PascalDragon
thanks for the info
nullable data types has at least 2 different open source implementations.

For starters here are two links
https://wiki.freepascal.org/Nullable_types
https://www.arbinada.com/en/node/1439

and I think I have one record based that is not generic based too somewhere.

PascalDragon

  • Hero Member
  • *****
  • Posts: 1742
  • Compiler Developer
Re: RTTI and record
« Reply #7 on: May 30, 2020, 01:38:41 pm »
And for completeness sake FPC trunk gained a Nullable unit two days ago as well (should be usable with FPC 3.2 as well).

 

TinyPortal © 2005-2018