DavidOne
Members-
Content Count
7 -
Joined
-
Last visited
Community Reputation
0 NeutralRecent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
Hello Dalija, thank you for your response! In the end I defined an event in the TMainDataModule and an event handler in the login form. I rewrite REST request execution in the following way: UserRESTRequest.ExecuteAsync( procedure begin var User: TUtente := TJson.JsonToObject<TUtente>(UserRESTResponse.Content); Self.OnAfterLoadUser(Self, User); end, True, True, procedure(Error: TObject) begin raise Exception.Create('It was not possible to contact the server'); end); What do you think about this solution? Is it really thread safe and may be a good workaround? Thank you, Davide
-
Hello, I am upgrading my Delphi VCL REST client to introduce async loginc in REST call which are now running in the main thread. I read some articles and docs but none of this put me in the right way. Starting from the simplest thing: the login, I amusing the following code: function TMainDataModule.LoadUser(AUserMailAddress: string): TUser; begin Result := nil; try UserRESTRequest.Params.ParameterByName('MailAddress').Value := AUserMailAddress; UserRESTRequest.Execute; if (UserRESTResponse.Status.Success) then Result := TJson.JsonToObject<TUtente>(UserRESTResponse.Content) except on E: Exception do raise Exception.Create('Non è stato possibile contattare il server'); end; end; If I use the TRESTRequest.ExecuteAsync or create a TTask and run the TRESTRequest.Execute inside I cannot assign the Result of my function (cause the function is execute in the main thread, I suppose...). What is the right way to execute the REST call and retrun the value of the call to the main thread? I have the same problem in assigning the result of a REST call data to my TMemTable. Have you got some advice or different approach about how to retrieve data asycronously? Thank you, Davide
-
Encoding accented char in JSON format
DavidOne replied to DavidOne's topic in Network, Cloud and Web
Thank you, setting the StringEscapeHandling to EscapeNonAscii does the magic! -
Hello, I am working with Delphi 11.1. Inspired by a Stephen Ball article I am using a TJsonTextWriter to create a RADServer endpoint response the contains data from a master-detail data relationship. To write field value in the Json text response I am using the following code: if ((ADataSet.Fields[FieldIdx] is TDateField) or (ADataSet.Fields[FieldIdx] is TSQLTimeStampField)) then Writer.WriteValue(ADataSet.Fields[FieldIdx].AsDateTime) else Writer.WriteValue(ADataSet.Fields[FieldIdx].AsString); The problem I am facing off is about accented characters like: à. When I retrieve data from the endpoint I receive the following error: Project Test.exe raised exception class EEncodingError with message 'No mapping for the Unicode character exists in the target multi-byte code page'. If the there are no accented chars in the field content I can read the resulted Json without any problems. How should I managed to encode correctly accented chars? Thank you, Davide
-
Thank you, it solved the error!
-
Hello, I am developing on Delphi 11.1. I would like to read a JSON pair REST response received by TRESTResponse object. The response has the following format: {"OrderNo", "W00001987"}. In my first attempt to get the OrderNo value I used this code: OrderNoRESTResp.RootElement := 'OrderNo'; var S: string := OrderNoRESTResp.Content; Result := OrderNoRESTResp.JSONValue.ToString; But in the result were reported the double quotes aoround the order no. After I try with the following code and I get the right order no without double quotes: Jsv: TJSONValue := OrderNoRESTResp.JSONValue; try var Jso: TJSONObject := Jsv as TJSONObject; for var JPair: TJSONPair in Jso do Result := JPair.JSONValue.Value; Is the above code the correct one and the best way to retrieve a single Json pair returned from the TRESTResponse ? Thank you, Davide
-
Hello, I am working with Delphi 11.1 on a Windows 11 Pc. I downloaded the "Low code wizard 1.0" from the Get it and I created a mobile project using the wizard. When I try to run the project I get the following error: Project LowCodeTest.exe raised exception class EListError with message 'Duplicates not allowed'. I try to enable and disable different option in the wizard but the error remains there. Has somebody aleady encoutered and solved this problem? Thank you, Davide