[fpc-pascal] Re: JSON & me - blind again?
Michael Van Canneyt
michael at freepascal.org
Tue Mar 12 12:17:19 CET 2013
On Tue, 12 Mar 2013, Reinier Olislagers wrote:
> On 12-3-2013 11:44, Michael Van Canneyt wrote:
>
> Thanks for the help, Michael.
>
>> On Tue, 12 Mar 2013, Reinier Olislagers wrote:
>>> //===> 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'.
> Understood. Then it has a pointer pointing to whatever (probably the
> object's former memory location).
>
>>> 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!
>
> Sorry. What I hadn't attached is the first part where the request is
> built up:
> if Assigned(AData) then
> begin
> VHttp.RequestBody := TMemoryStream.Create;
> VJSON := AData.AsJSON;
> VHttp.RequestBody.Write(Pointer(VJSON)^, Length(VJSON));
> VHttp.RequestBody.Position := 0;
> end;
Yes, but as per your code: you free and rebuild:
FreeAndNil(AData);
VData.Position := 0;
-> so you change the parameter, and thus you need a var/out
Anyway, glad it is fixed.
Michael.
More information about the fpc-pascal
mailing list