SaveObjectToJsonStream - is it working?

Hello,

I am trying to serialize into a readable text the parameters (structures) that arrive into my services when some error occurs, and I saw the function SaveObjectToJsonStream in the uROJSONUtils unit, which sounds exactly what I need.

But I haven’t been able to use it. I always get an Access Violation when trying to use it, no matter the object passed to the function. I am calling it from C++Builder, so I don’t know if that’s maybe some of the problem?

I ran a grep on the RO units to see if it’s being used anywhere and couldn’t find anything except the declaration/definition on said unit. So I wonder if it’s being used anywhere, by anybody?

Hi,

this unit is used for saving TDASchema into json.

example:

var
  str: TROBinaryMemoryStream;
  schema: TDASchema;
begin
  schema := TDASchema.Create(nil);
  schema.LoadFromFile('Y:\Schema.daSchema');
  str := TROBinaryMemoryStream.Create;
  SaveObjectToJsonStream(schema, str, ['Name']);
  writeln(str.ToString);
  str.Free;
  schema.Free;

note: it can be unsuitable for other classes

I think the problem here is some incompatibility with C++Builder. I made a simple test case in C++ that attempts to serialize a TForm using this function, and it fails exactly the same as when trying to serialize a RO structure.

But the same thing works in a Delphi project.

I don’t have RO compiled with debug info, so I haven’t been able to debug and at least try to see where this is failing. I’ll see if I can make some time to try this next week.

Meanwhile: my objective here is being able to log the structure/params sent to a service in case some error happens. Is there any other function on RO that would help in this case? I mean, to serialize a ROComplexType derived class to text. The format is not really important (although I was happy with the idea of having JSON).

Thanks!

Hi,

looks like you are right - some code can be incompatible with C++Builder because form is saved to json w/o errors:


You can use ROComplexType.ContentAsXml or ROComplexType.ContentAsString properties.

Hello Evgeny,

How could I enable debug info for the RO-SDK? To see if I can pin point where the problem is.

You can use ROComplexType.ContentAsXml or ROComplexType.ContentAsString properties.

That’s great! I’ll try adding this functions and see if that solves my issue, but I guess it will work just fine. Thanks!

Edit: I tried the properties you mentioned and they give me the info I need. So that solves my original issue.

In any case, if you can please comment on how to enable debug info for RO so I can try to workaround the AV with the JSON serializer, that would be great.

Hi,

some ROD units have {.DEFINE unitname_debug} defines like

{.$DEFINE uROAsyncSocket_debug}

it allows to have some additional details via OutputDebugString method
but JSON units haven’t such defines …


I see that uROJSONUtils.pas has {.$UNDEF ROUseGenerics} so you can

  • uncomment this define in this unit
  • rebuild c++builder files with C:\Program Files (x86)\RemObjects Software\Build\install_DA.cmd (or install_RO.cmd). launch this .cmd with admin rights
  • retest

not sure if it change anything

Hello Evgeny,

Thanks for the info.

I was thinking more about compiling the units/packages with debug info enabled. It appears they are not, at least here in my installation, as I can’t “step into” the unit when debugging. I don’t know if there is a global define/setting to enable and re-run install_RO.cmd, or I have to modify the projects directly?

Hi,

looks like you mean these switches of compiler:

Compiler switches: -$<letter><state> (defaults are shown below)
  D+  Debug information             
  L+  Local debug symbols           
  O+  Optimization                  

so update c_EW.train as

function buildRODelphiDCU(_version, _platform, _isindy9,_cbuilder)
..
function getCBuilderKeys(_version, outpath, isbpl)
..
  if (_version >= 10) return (isbpl) ? ' -JPHNE -JL "-NH%out%" "-NO%out%" "-NB%out%"'.replace("%out%",outpath) : ' -$D+ -$L+ -$O- -J -JPHNE "-NH%out%" "-NO%out%" "-NB%out%"'.replace("%out%",outpath);

after this re-run install_RO.cmd