I very much would like to keep it all in one routine like molly suggests, but TBaseJSONReader only allows the parsing to go to the next step by returning from its KeyValue, StingValue, etc. methods. Molly doesn't have this problem because she is traversing the JSONData structure, and I'm trying to avoid building that structure.
I got it working with:
PJSONCallback = ^TJSONCallback;
TJSONCallBack = procedure(const JSONValue : TJSONValue; CallBack : PJSONCallback) of object;
It's a good solution that doesn't require casting. I had forgotten that you can create pointer types before defining the type.
I found some odd bugs/unintended features.
When I call the callback function I have to use two "@"s
Callback(JSONValue,@@NextCallback);
The first one still returns the function pointer. I add two to get the pointer to the function pointer. This probably isn't a bug, just an oddity of the language.
When I try to use a record method as the callback function, I get this error.
Error: Incompatible types: got "TArrayOfObject.Scallback(const TJSONValue;PJSONCallback);" expected "<procedure variable type of procedure(const TJSONValue;PJSONCallback) of object;Register>"
However, when I use a record helper method, it works.