On Tue, 12 Mar 2013, Reinier Olislagers wrote:
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
It is assigned, but not necessarily valid. If you freed CommJSON but did not nil it, it is still'assigned'.
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;
Ehm. This must be function HttpRequestWithData(OUT AData: TJSONData; const AUrl: string; const AMethod: TRequestMethod; const AContentType: string): THttpResult; Because you are passing BACK a reference! Michael. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal