Jump to content

Recommended Posts

Posted
I have a UniForm (UniForm2) that I am trying to send an AjaxEvent to update my ProgressBar (pg).

 

The Form's AjaxEvent code is firing on: active, move, resize etc. as expected.

 

It will not fire on my custom EventName 'update' sent via my UpdateJobProgress procedure, please advise how to resolve - thanks in advance.

 

 


procedure TJobThread.Execute; // This will be extended when the basics work

begin

  Progress:= 0;

  while not Terminated and (Progress < 100) do begin

    Inc(Progress);

    Sleep(50);

  end;

end;

 


function TUniForm2.DoSomething(): Boolean;

 

...

 


  //

  if Assigned(job) then begin

    if not (job.Finished or job.Terminated) then begin

      job.Terminate;

    end;

    job.Free;

  end;

  //

  job:= TJobThread.Create;

  job.FreeOnTerminate:= False;

  UniSession.AddJS('UniForm2.pg.updateProgress(0.0, ''Running...'', false);');

  UpdateJobProgress;

 

...

 

  BUSY WORKING HERE

...


 

end;

 

procedure TUniForm2.AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);

begin

  if EventName = 'update' then begin

    MessageDlg(EventName, mtWarning, [mbOK]);

    UniSession.AddJS(Format('UniForm2.pg.updateProgress(%d/%d, ''Running...'', true);', [job.Progress, 100]));

    //

    if not (job.Finished or job.Terminated) then begin

      UpdateJobProgress;

    end else begin

      if job.Progress = 100 then begin

        UniSession.AddJS('UniForm2.pg.updateProgress(1.0, ''Done'', true);');

      end else begin

        UniSession.AddJS(Format('UniForm2.pg.updateProgress(%d/%d, ''Stopped by user'', true);', [job.Progress, 100]));

      end;

    end;

    //

  end;

end;

 

procedure TUniForm2.UpdateJobProgress;

begin

  UniSession.AddJS('setTimeout(function() { ajaxRequest(UniForm2.form, ''update'', []) }, 200)');

end;

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...