Mega Search
23.2 Million


Sign Up

Make a donation  
Re: How to combine JQuery UI and IntraWeb AJAX [Edit]  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb

You cannot use a callback in a form that is used in another form, you have a call back per form, remember each form
is a new webpage, so there is no problem registering again the callback it will be substituted. unless you create a global 
procedure in another unit and have a public variable that will contain the current TIWForm viewed. so it can be accessed by
the callback method. but I think it is better if you copy the callback method code from form1 and add it to form2.

Also you can create a new class like TIWMyEditCallBack in an external unit, and add the callback procedure as a method, just add a 
Constructor Create with a parameter to pass the current IWForm and store it in a variable/field like 'fIWForm: TIWForm'.

{code}
type
 TIWMyEditCallBack = class(tobject)
 protected
  fIWForm: TIWForm
 public
  constructor Create( AForm: TIWForm );
  procedure AjaxHandler(EventParams: TStringList); 
 end;
{code}


Change the callback procedure code  to search in the stored form reference.
so ti should look something like this
{code}
procedure TIWMyEditCallback.AjaxHandler(EventParams: TStringList);
  var c,v:String;
      zControl:TIWControl;
begin
  c:=EventParams.Names[1];
  if (c<>'') AND
    (fIWForm.FindComponent(c)<>nil)
    then
    begin
      zControl:=TIWControl(fIWForm.FindComponent(c));
      if zControl.ClassNameIs('TIWEdit') then
        begin
          TIWEdit(zControl).Text:=EventParams.Values[c];
          TIWEdit(zControl).refresh;
          //other stuff
        end;
    end;
end;
{code}

Then instantiate this class per form in the OnCreate event of the form and destroy it in the OnDestroy event of the form

You can have this object as a property or field of a form:
{code}
fMyEditCallBack :=  TIWMyEditCallBack.Create(self); //self is the current IWForm;
{code}

In the OnRender event of the form Register the callback, so it will re-register it even if the form is not freed and called again
{code}
procedure TIWForm1.IWAppFormRender(Sender: TObject);
begin
 WebApplication.RegisterCallBack('IWEDIT1MyAjaxHandler', fMyEditCallBack.AjaxHandler);
end;
{code}

Edited by: Francisco Armando Dueñas Rodriguez on Jul 12, 2013 8:13 PM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Jul-2013, at 10:19 PM EST
From: =?Utf-8?Q?Francisco_Armando_Due=C3=