Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   TJSonObject Freigabe (https://www.delphipraxis.net/203762-tjsonobject-freigabe.html)

dataspider 20. Mär 2020 18:28

TJSonObject Freigabe
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo

Ich wollte mit privat schnell mal Währungskurse holen mit Fixer.io API.

Delphi-Quellcode:
procedure TFrmMain.Button1Click(Sender: TObject);
Var
  LHttp: THttpClient;
  LResp: IHttpResponse;
  LJObj: TJSonObject;
  LJRates: TJSonObject;
  LUrl: string;
  I: Integer;
begin
  LUrl := BaseUrl + 'latest?access_key=' + Key + '&symbols=USD,GBP,NOK,HKD&format=1';
  LHttp := THTTPClient.Create;
  try
    LResp := LHttp.Get(LUrl);
    LJObj := TJSONObject.ParseJSONValue(LResp.ContentAsString(TEncoding.UTF8)) as TJSONObject;
    try
      LJRates := LJObj.GetValue<TJSONObject>('rates');
      try
        for I := 0 to LJRates.Count - 1 do
        begin
          Memo1.Lines.Add(LJRates.Pairs[I].JsonString.Value);
          Memo1.Lines.Add(LJRates.Pairs[I].JsonValue.Value);
        end;
      finally
        LJRates.Free;
      end;
    finally
      //LJObj.Free;
    end;
  finally
    LHttp.Free;
  end;
end;
Will ich LJObj freigeben, erhalte ich eine AV.
LJRates kann ich freigeben.

Aber was ich auch mache, am Ende erhalte ich beim Verlassen Memory Leaks.
Was mache ich falsch?

Danke

Frank

DeddyH 20. Mär 2020 20:12

AW: TJSonObject Freigabe
 
Versuch mal, LJObj freizugeben, aber nicht LJRates. Letzteres ist ja ein Kindobjekt des Ersteren und wird von diesem automatisch mit freigegeben, deshalb auch die AV.

dataspider 21. Mär 2020 09:21

AW: TJSonObject Freigabe
 
:oops:
Vielen Dank, genau so funktioniert es!


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:13 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz