Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   liberando RESTResponse (https://www.clubdelphi.com/foros/showthread.php?t=95150)

balger 08-04-2021 23:38:46

liberando RESTResponse
 
Hola gente.
Tengo el sig. problema.
En una clase creo y destruyo los componentes REST y OAuth. el tema es que el hacer RESTResponse1.free recibo error de memoria
aparentemente tengo un problema con un objeto TJSon.
Espero ansioso sus comentarios.
Desde ya muchas gracias

Neftali [Germán.Estévez] 09-04-2021 10:16:15

Deberías añadir el código que estás utilizando, tanto para crear los componentes como para destruirlos.
De otra forma, sólo con el texto el casi imposible saber cual es el problema y cual puede ser la solución.

balger 09-04-2021 15:35:47

Gracias por responder. Por suerte pude resolver el tema.
La cosa esquemática es así

Código Delphi [-]
types
  Clase1 = Class
     RESTClient1: TRESTClient;
     RESTRequest1: TRESTRequest;
     RESTResponse1: TRESTResponse;
     OAuth2Authenticator1: TOAuth2Authenticator;

 private
    procedure ReqsSetBody;

  public 
     procedure create
     procedure destroy 
end

procedure create
  RESTClient1 := TRESTClient.Create(nil);
  RESTRequest1 := TRESTRequest.Create(nil);
  RESTResponse1 := TRESTResponse.Create(nil);
  OAuth2Authenticator1 := TOAuth2Authenticator.Create(nil);
end

procedure destroy
  FreeAndNil(OAuth2Authenticator1);
  FreeAndNil(RESTRequest1);
  FreeAndNil(RESTResponse1);
  FreeAndNil(RESTClient1);
end

procedure ReqsSetBody
var  
  jsnBody: TJSONObject;

begin
  jsnBody := TJSONObject.Create;
  try
    jsnBody.AddPair(lowercase(f.FieldName), VarToStr(Trim(f.Value1)));
    jsnBody.AddPair(lowercase(f.FieldName), TJSonNumber.Create(f.Value2));
    jsnBody.AddPair(lowercase(f.FieldName), DateToISO8601(f.Value3, True));

    RESTRequest1.AddBody(jsnBody);
    
  finally
    jsnBody.Free;
 end;

end;

El problema fue resuelto cambiando la visibilidad de (y todo lo que involucra)
var jsnBody: TJSONObject en procedure ReqsSetBody

a la sección privada de la clase y agregando su creacion a procedure create.

Desconozco si existe una mejor opción.


La franja horaria es GMT +2. Ahora son las 12:51:40.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi