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.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal