Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Registered callback methods
#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


Messages In This Thread
RE: Help with Registered callback methods - by LeoBruno - 08-17-2019, 12:32 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)