TWebHTTPRequest OnRespose function by code

Hi,

I use the component TWebHTTPRequest by insert its visual control in the Desing mode of the DataModule. Then i active the Event OnResponse and i program the code for manage the response of server.

Now i want to use this mechanism only with code.

I want create a funcion inside the code of DataModule that i can Create an instance of the TWebHTTPRequest, assign properties and execute it.

I can do without problem.

But i do not know how can i assign a OnResponse function to manage the response.

I see that in the Execute method of TWebHTTPRequest.Execute() i can send a parameter of type THTTPResponseProc but i do not know how can i use it.

Can you help me ?

Thanks.

Execute() can be called with an anonymous method:

Example:

begin
  webhttprequest1.Execute(
     procedure(AResponse: string; ARequest: TJSXMLHttpRequest)
     begin
       console.log(AResponse);
     end
  );
end;

Ok. I try it.

Then is not possible set a function name (or pointer to a function) like in the TWebForm.CreateNew method ?

---> NewFormToCreate:=TclassFNewForm.CreateNew(@AfterCreate)

In other words. This code is not possible ?:

procedure TForm1.HTTPServer...
var
x: integer;

procedure GetResponse(AResponse: String; ARequest: TJSXMLHttpRequest)
begin
console.log(AResponse);
end;

begin
webhttprequest1.Execute(@GetResponse);
end;

I do not understand why you want to make these things so complex.
You can simply assign your OnResponse event handler just like in classic VCL/Delphi

WebHttpRequest.OnResponse := MyEventHandler;

Hi Bruno,

Sorry for the delay of this response...

Is true that you say... My mechanism is so complex. I have used the one you propose to me and it is much clearer...

Thanks !