Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Registered callback methods
#1
Hi:

I´m testing Intraweb 15.1 and

I need to get on server side (IWApplication) the result value from a javascript function executed on client side.

I have read this dodumentation http://docs.atozed.com/docs.dll/developm...015.1.html
and these threads https://www.atozed.com/forums/showthread.php?tid=498 , https://www.atozed.com/forums/thread-1134.html

Also IW CustomAjaxCall Demo.

But I find all very confusing, because i need the return values on server side.
So Why should I use a callback method, when all I need to do is to get a result value that is on the client side?
Also, I´m not sure if I got this right.

Here is what I have so far...

1- the CallBackMethod:

procedure TfrmBase.clbkGridSel(aParams: TStrings; out aResult: string);
begin
  aResult := aParams.Values['Selection'];
end;


2 - the registration of the callback method

procedure TfrmBase.IWAppFormCreate(Sender: TObject);
begin
  WebApplication.RegisterCallBack('clbkGridSel', clbkGridSel);
end;


How do I get, on server side, the aResult from the callback method to process this information?

I wrote this method to execute the callback on client side, but as you can see, It doesn´t help me to get the information.

function TfrmBase.GetSelecaoGrid: string;
begin
  WebApplication.
    CallBackResponse.
      AddJavaScriptToExecute('ajaxCall("clbkGridSel", "&Selection="  + GRIDCADUSUARIOGetSelected()');
end;

GRIDCADUSUARIOGetSelected() id the javascript function that will return the selected data.

In other words, what I need to accomplish, is to be able to call javascript "GRIDCADUSUARIOGetSelected() " from Server Side, and get it´s result value.
Reply
#2
Hi Leo. Try this:
Code:
procedure TfrmBase.IWAppFormCreate(Sender: TObject);
  RegisterCallBack('clbkGridSel',
    procedure (aParams: TStrings; out aResult: string)
    begin
      aResult := aParams.Values['Selection'];
    end
  );
end;
Reply
#3
(08-16-2019, 09:06 PM)Jose Nilton Pace Wrote: Hi Leo. Try this:
Code:
procedure TfrmBase.IWAppFormCreate(Sender: TObject);
  RegisterCallBack('clbkGridSel',
    procedure (aParams: TStrings; out aResult: string)
    begin
      aResult := aParams.Values['Selection'];
    end
  );
end;

Hi Jose, thanx for your reply.

If you take a closer look, you'll see that I already registered the callback method, but instead of registering an anonymous method, I have registered the method TfrmBase.clbkGridSel;

Anyway, I realized what I was doing wrong.

First, I changed the javascript, to include the call of the callback method, after obtaining the result.

Then, altered a bit the code, since the out parameter was useless in this case.

From this part, assume that the CallBack Method is already registered. From now on, I'll only post the code which I need help with.

Here is the refactored callback method:
Code:
procedure TfrmBase.clbkGridSel(aParams: TStrings);
begin
  fGridSelection := aParams.Values['Selection'];
end;
It gets the value and set the protected formclass field fGridSelection;

Now, on the AsyncClick event of a button, I call the following method:
Code:
function TfrmBase.GetSelecaoGrid(aHtmlID: string): string;
begin
  fGridSelection := '';

  WebApplication.
    CallBackResponse.
      AddJavaScriptToExecute(aHtmlID + 'GetSelected()');

  /// here I need to wait for the form class protected field "fGridSelection" to obtain the returned value

  result := fGridSelection;
end;
It's not working, because it sets the result, before the "fGridSelection" field receives it´s value.

I don't want to reload the form.

So, how do I achieve this?
Reply
#4
Hi Leo. I made a demo using callback on AsyncClick.
Code:
procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
   WebApplication.RegisterCallBack('clbkGridSel', clbkGridSel);
end;

procedure TIWForm1.clbkGridSel(aParams: TStrings );
begin
  fGridSelection := aParams.Values['Selection'];

  WebApplication.
  CallBackResponse.
   AddJavaScriptToExecuteAsCDATA( 'document.getElementById("IWEDIT1").value = "' + fGridSelection + '"' );

  WebApplication.ShowNotification( fGridSelection );
end;

procedure TIWForm1.IWButton1AsyncClick(Sender: TObject;
  EventParams: TStringList);
begin
  WebApplication.
  CallBackResponse.
   AddJavaScriptToExecute( 'ajaxCall("clbkGridSel", "Selection=something", false);' );
end;


Attached Files
.zip   LeoBruno.zip (Size: 57.01 KB / Downloads: 14)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)