Author Topic: ToStr - Convert any value to String using RTTI  (Read 4958 times)


  • Hero Member
  • *****
  • Posts: 7807
Re: ToStr - Convert any value to String using RTTI
« Reply #30 on: October 15, 2018, 02:31:47 pm »
Hellooho? I only use mode ObjFPC. Mode Delphi is only used for testing, cause aside from bugs (like the one with the overload here; did anyone report that already?) mode ObjFPC's generics are superior to the mode Delphi ones as one can use complex inline specializations that currently aren't possible in mode Delphi.
If that's indeed the case it would be a reason to me to revisit them if inlining is an issue, which it is sometime. Why is that not in {$mode delphi}, just curious? (I noticed it, but assumed objfpc suffered the same)
Otherwise I always use {$mode Delphi} because it is more concise and I maintain Delphi code too.
Ad Brexinitum (can't help it)


  • New member
  • *
  • Posts: 18
Re: ToStr - Convert any value to String using RTTI
« Reply #31 on: October 15, 2018, 09:42:04 pm »
I Improved the code based in Thaddy and ASerge(Awesome insights in your attached file) suggestions:

-Replaced 'var' by 'const'
-Moved 'FormatSettings' initialization to 'tkFloat' case.
-Removed useless string concatenations.
-Removed the need for the 'TypeData' variable.
-Added ifdef to handle a name change in trunk (ManagedFldCount to TotalFieldCount).

Tried to add the generic version but it dont compiled in 3.0.4 (i am not a trunk user for now).

I am thinking about the inclusion of custom formatting but there's just too many options:
- Integers can be binary, octal or hexadecimal hexadecimal...
- Floats already have formatsettings...
- Booleans can be 0 or 1 ou true or false...
- Custom delimitters
My main inspiration to write this was 'console.log' in javascript or python 'print' and there's no way to format the output in this functions (as they are used for logging and debugging, not serialization). I think that cases where this type of fine tuning is needed you cant escape but write your own ToString in a TypeHelper or advanced record or whatever...
« Last Edit: October 15, 2018, 10:02:52 pm by correa.elias »