Jump to content

John Gambler

Members
  • Content Count

    3
  • Joined

  • Last visited

Everything posted by John Gambler

  1. John Gambler

    Pointer variable erros

    I'm having some difficulty using variables through their memory addresses. In the test below, the pointer of the ParamEmbeddedRec variable and the Params variable (inside ParamMaster) should be the same, so the value of PatchParam and Payload (inside ParamEmbeddedRec) are invalid. I think the syntax of line 47 (ParamMaster.Params := @ParamEmbedded) is not correct. Bellow, my code and an image of the debug, My code: unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); Type TParamMaster = Record Operacao : Smallint; Params : Pointer; End; Var ParamMaster : ^TParamMaster; Type TParamEmbedded = Record PatchParam : String; Payload : String; End; Var ParamEmbedded : ^TParamEmbedded; Var ParamEmbeddedRec : ^TParamEmbedded; begin New(ParamMaster); New(ParamEmbedded); ParamEmbedded.PatchParam := 'somePatch'; ParamEmbedded.Payload := '{"aooCode": "F60EB930-9B1B-11EF-9657-02240D86274B"}'; ParamMaster.Operacao := 1; ParamMaster.Params := @ParamEmbedded; ParamEmbeddedRec := ParamMaster.Params; Dispose(ParamEmbedded); Dispose(ParamMaster); end; end.
  2. John Gambler

    TRESTClient encode issue

    I have a small program(code bellow) to communicate with a rest API, everything works fine. My problem now is how can i fix the response values with diacritic character. Examples: correct string: não - received string: n\u00E3o correct string: padrão - received string: padr\u00E3o My code: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Edit, FMX.Controls.Presentation, FMX.StdCtrls, REST.Types, Data.Bind.Components, Data.Bind.ObjectScope, REST.Client, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo, System.JSON; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Send(Url : String); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.Send(Url : String); Var myClient : TRESTClient; myRequest : TRESTRequest; myResponse : TRESTResponse; Content : String; Begin myRequest := TRESTRequest.Create(Application); myResponse := TRESTResponse.Create(Application); myClient := TRESTClient.Create(nil); myRequest.Client := myClient; myRequest.Response := myResponse; Try myRequest.AddParameter('Content-Type', 'application/json', TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]); myRequest.AddParameter('Accept', 'application/json', TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]); myRequest.Method := TRESTRequestMethod.rmPOST; Content := '{"emptyString": "", "someUuid": "F60EB930-9B1B-11EF-9657-02240D86274B"}'; myRequest.Params.AddItem('body',Content,TRESTRequestParameterKind.pkREQUESTBODY,[],ctAPPLICATION_JSON); myRequest.Resource := Url; myRequest.Execute; Memo1.Lines.Add('objectProperty1: ' + (myResponse.JSONValue as TJSONObject).GetValue('objectProperty1').ToJSON()); Memo1.Lines.Add('objectProperty2: ' + (myResponse.JSONValue as TJSONObject).GetValue('objectProperty2').ToJSON()); Finally Resposta.Free; myRequest.Free; myClient.Free; End; End; procedure TForm1.Button1Click(Sender: TObject); begin Send('http://localhost:4000/local/'); end; procedure TForm1.Button2Click(Sender: TObject); begin Send('https://mystackurl.com'); end; End.
  3. John Gambler

    TRESTClient encode issue

    Thank you Remy and Uwe, both ways worked ok.
×