Hey HeavyUser,
1) the more calls you add the slower you code becomes.
Thanks for the tip. I'll keep this in mind when doing code that is called many times in a cycle.
This code is mainly for marshalling and un-marshalling from
JSON <-->
TObject.
Nothing that needs any speed tuning, I guess
2) the prefix T is used only on type definition not on variables.
Shuck, mate, thanks!! Now I feel embarrassed for the stupid mistake. Let's put it down to being too early in the morning when I typed the code, LOL!!!
I've corrected the code to display the appropriate
F for field.
3) If you do use the initializeFields idea do make sure that at least its virtual.
I think I've never fully understood what virtual means and how best to use it. Could you elaborate or point me out for a good quick refresher?
Many thanks in advance!!
Personally I used both methods, I used your second method in c++ where I had problems with virtual constructors and your first method as my primary go to method in pascal.
Good to know, many thanks!!
In short do not break your methods unless absolutely necessary and in your example breaking the initialization code out to a 3rd method is excessive.
The only way that might be acceptable if you had a reset method of some sort.
I agree that, in this very simplistic example, the
InitiateFields method is a bit of an overkill.
But in my full code there are methods to
LoadFrom[JSON|JSONData|JSONObject|JSONArray], which in my opinion, needs the
InitiateFields as a reset button.
I will take you tips onboard as they are quite useful.
Many thanks for them!!
Cheers,
Gus