Hi list,

(FPC 2.6.0 or trunk)

Been fiddling a bit too long and strongly suspect PEBKAC/PICNIC (and my
seemingly perennial refusal to adapt to Object Pascal's way of dealing
with object references).

Thanks for your suggestions!


See the ===> marks below

var
  CurrentPage: integer;
  RequestResult: THttpResult;
  CommJSON: TJSONObject;
begin
  result:=INVALIDID;
  CommJSON:=TJSONObject.Create;
  try
    try
// do an HTTP request and get a JSONData back.
//
RequestResult:=HttpRequestWithData(CommJSON,FCGIURL+'document/',rmPost);
      if RequestResult.Code<>200 then
      begin
//snip error handling
      end
      else
      begin
//===> the line below works - so CommJSON is a valid object, right?
        if Assigned(CommJSON) then
        begin
//====> however, the next line gives a runerror(210): no vmt found
          if (CommJSON.JSONType=jtObject) then
          begin
            if (CommJSON.IndexOfName('documentid',false)>-1) then
              result:=CommJSON.Integers['documentid'];
          end;
        end;
      end;


I'm not confident about
function HttpRequestWithData(AData: TJSONData; const AUrl: string;
  const AMethod: TRequestMethod; const AContentType: string): THttpResult;
...
      FreeAndNil(AData);
      VData.Position := 0;
      VParser := TJSONParser.Create(VData);
      try
        try
          AData := VParser.Parse;
//====> so it destroys the object passed to it and recreates it
//====> but AData.JSONType does seem to be JSONObject...
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to