Possible bug on fpjson's TJSONData object lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-05-20 14:14 Hey all, Can someone please explain to me what I'm doing wrong here? Attached is a personal project that aims to implement the JSON-RPC v2.0 to use in a Stratum protocol. On the tests you find this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TNosoPoolStratumJSONRPCRequest.CheckFieldsCreateWithMethod;begin  AssertEquals('Request '+cjJSONRPC+' is '+cjJSONRPCversion, cjJSONRPCversion, FRequest.JSONRPC);  AssertEquals('Request '+cjMethod+' is mining.authorize', 'mining.authorize', FRequest.Method);  AssertNotNull('Request '+cjParams+' is not null', FRequest.Params);  AssertEquals('Request '+cjParams+' count is 2', 2, FRequest.Params.Count);  { TODO 100 -ogcarreno : Why does this go BOOM only here ?!?!?! }  AssertEquals('Request '+cjParams+' item[0] is "login""', 'login', FRequest.Params[0].AsString);  AssertEquals('Request '+cjParams+' item[0] is "password""', 'password', FRequest.Params[1].AsString);  AssertEquals('Request '+cjID+' is 1', 1, FRequest.ID);end;  And on that line it gives an Access Violation. Why is the default property erroring out? The code that builds the TJSONArray is this(Marked where the TJSONArray is manipulated): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TRequestParamsArray.setFromJSONObject(const AJSONObject: TJSONObject);var  jData: TJSONData;  jParams: TJSONArray;  index: Integer;begin  jData := AJSONObject.Find(cjJSONRPC);  if Assigned(jData) then  begin    FJSONRPC:= AJSONObject.Get(cjJSONRPC, FJSONRPC);  end  else    raise ERequestMissingMember.Create(Format(rsExceptionMissingMember, [cjJSONRPC]));   jData := AJSONObject.Find(cjMethod);  if Assigned(jData) then  begin    FMethod:= AJSONObject.Get(cjMethod, FMethod);  end  else    raise ERequestMissingMember.Create(Format(rsExceptionMissingMember, [cjMethod]));   jData:= AJSONObject.Find(cjParams);  if Assigned(jData) then  begin    if jData.JSONType = jtArray then    begin      jParams:= TJSONArray(jData);      FParams.Clear;      for index:= 0 to Pred(jParams.Count) do      begin        FParams.Add(jParams[index]);      end;    end;  end  else    raise ERequestMissingMember.Create(Format(rsExceptionMissingMember, [cjParams]));   jData:= AJSONObject.Find(cjID);  if Assigned(jData) then  begin    FID:= AJSONObject.Get(cjID, FID);  end  else    FNotification:= True;end;  I've tried many things to debug this but I've exhausted my meagre means. Can anyone help please? Cheers, Gus ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-05-22 01:00 Hey all, I've since modified the names of this code to implement the v2.0 of JSON-RPC as a stand-alone lib I can then use in other parts. I've put the code on GitHub: https://github.com/gcarreno/lazJSONRPCData/ I've also banged my head several times against many floating errors. The ones you add a blank line and your code explodes in a different place. I've even had a private field of TRequest change from TJSONData to TJSONString after Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Result.Add(cjJSONRPC, cjJSONRPCversion);) And those are both string constants. The curious is that the field would then assume the role of a TJSONString with the value of cjJSONRPCversion. I then choose to have FParams as a string, not a TJSONData and ALL my errors go away!!! What kind of black magic have the devs used to implement TJSONData!?!?!? I'll keep at it, but I really need that FParams is TJSONData and that just messes up the whole thing!!! I really need some help here, sorry!!! I'm really sorry if I seem a desperate beggar, but the fact of the matter is... well I am!!! Cheers, Gus ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-05-22 01:32 Hey all, I've solved my problem, but I'm million of miles from understanding why the code behaved in that way; In the end my solve was this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i interfacetype   TRequest = class(TObject)  private  {...}    FParams: TJSONStringType;  {...}    function GetParams: TJSONData;  public    property Params: TJSONData      read GetParams;  end; implementation function TRequest.GetParams: TJSONData;begin  Result := GetJSONData(FParams);end;  So storing internally as a TJSONStringType and having a getter return the TJSONData object that I wanted, miraculously gets all those testes on the green I'm baffled and stumped and I can't begin to know where to begin to investigate  this. Cheers, Gus