views:

266

answers:

2

Scenario: I have a Delphi Intraweb application that has some edit components and buttons on a screen. In the TIWEdit.OnAsyncExit and TIWButton.OnClick a flag is set, and another thread in the application sets the enabled properties of the buttons depending on the flags and some other application data.

By the time the TIWButton.Enabled properties are set, the request has already finished and the next interaction is cancelled as IW finds out that internal representation and HTML form are out of sync. It resynchonizes and you have to click again.

I would like to refresh the screen somehow on demand.

  • A timer that finds out whether the two are synchronized and issues a refresh has drawbacks in traffic and timing (I can click a button before a timer run).
  • A method that could push data would be great.
  • Maybe IW has a possibility to do an non-save sync without cancelling the action I just committed.

As my screens are built model driven (I cannot predict what components will be on the screen and what the interdependencies between components are, that is in the business logic), I cannot add JavaScript to enable or disable a button depending on user actions.

+1  A: 

I am not completely sure if your question is the same as mine, yet I think there is a lot in common. See the demo project (v2) I posted in the Intraweb forum.

Based on some comments from Jackson Gomes I enable a TIWTimer before a long running thread starts and disable this after the thread has ended. See: http://forums3.atozed.com/IntraWeb.aspx (atozedsoftware.intraweb.attachments), thread 'IWLabel update via Thread', Oct 15, 2009.

The OnASync timer event is fired every 500 ms and is using some bandwith. Acceptable in my situation (company intranet).

Gert

Gert de Boom
Sorry, this will not do it for me as I am out in the wild with substantial traffic at times. But thanks for the answer.
Ralph Rickenbach
A: 

You could use the Interop Web Module from the IWElite component pack.

Essentially you would write a bit of Javascript using the XMLHTTPRequest (XHR) object to call into your IW app's Web Module Action which returns when the processing is finished. If you need your IW app to continue to function as normal while the process is running, your Javascript could open a progress window and make the XHR call from there.

IW Elite can be found here: http://code.google.com/p/iwelite/

An XHR request would look something like this:

function NewXHR() {
  if (typeof XMLHttpRequest == "undefined") {
    try { return new ActiveXObject('Msxml2.XMLHTTP.6.0');} catch(e) {}
    try { return new ActiveXObject('Msxml2.XMLHTTP.3.0');} catch(e) {}
    try { return new ActiveXObject('Msxml2.XMLHTTP');} catch(e) {}
    try { return new ActiveXObject('Microsoft.XMLHTTP');} catch(e) {}
    throw new Error('AJAX not supported in this browser.');
  } else {
    return = new XMLHttpRequest();
}

var xhr = NewXHR();
xhr.open("get", '/mywebaction', false);
xhr.send(null);
window.alert(xhr.responseText);

The above code will block and wait for the response. If you would rather have it act asynchronously, you could instead do the following:

var xhr = NewXHR();
xhr.open("get", '/mywebaction', true);
xhr.onreadystatechange = function() {
  if(xhr.readyState == 4) {
    if ((xhr.status == 200) || (xhr.status == 304) || (xhr.status === 0)) {
      window.alert('Success: '+xhr.responseText);
    } else {
      window.alert('Error: ('+xhr.status+') '+xhr.statusText;
    }
  }
};
xhr.send(null);
Jason Southwell