Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: RealTime data



Permlink Replies: 4 - Last Post: Mar 22, 2018 7:13 AM Last Post By: Mirco Malagoli Threads: [ Previous | Next ]
Mirco Malagoli

Posts: 4
Registered: 5/13/00
RealTime data
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 10, 2018 1:09 PM
Hi, I need to build a web application to show the data from a car race.
I tryied to write a IWgrid cells whit data every time I find a lap from my application but the data is not refreshed until F5 on browser.
I have tryied to use a IWtimer to refresh the grid once a second but in this case i find many runtime error on timer and the data sometime have many second of delay and jump across time (AJAX request failed. The application server did not respond. IWTIMER.DoOnAsyncTimer).
I need also to show a time of race every second.
There is a best way to implement this?
I have found other problem when i use a parameter to tell the server witch data to show "x.x.x.x:8888/$/?id=x"
If i change the id the session the page do not refresh and the data come from the same usersession until I close and reopen the browser.

C++10 iw 14.2

Thanks for your help
Mirco
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: RealTime data
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 10, 2018 3:00 PM   in response to: Mirco Malagoli in response to: Mirco Malagoli
I would start over with a simple proof of concept. Just start with a timer and a label. Try updating the label in the timer event.

There is nothing in IW that would prevent this from working. It must be a combination of controls and events that is causing the issues. One common problem is not disabling the timer while work is being done. By not doing that you will have multiple threads running at the same time.

Example:

procedure TFormCouponFace.IWTimer1AsyncTimer(Sender: TObject; EventParams: TStringList);
begin
   IWTimer1.Enabled := false;
   try
   //Do your work and processing here...
   finally
     IWTimer1.Enabled := true;
   end;
end;
Mirco Malagoli

Posts: 4
Registered: 5/13/00
Re: RealTime data
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 11, 2018 8:44 AM   in response to: Daniel Fields in response to: Daniel Fields
Sorry, Im new to intraweb
I have tryied "File->New->Other->Intraweb Application Wizard"
In the IWForm1 I have put only a IWLabel and IWTimer.

This is the only code i have added to a form.
</div>
void __fastcall TIWForm1::IWTimer1AsyncTimer(TObject *Sender, TStringList *EventParams)
{
	IWTimer1->Enabled= false;
	try
	{
		IWLabel1->Caption= TimeToStr( Time());
	}
	__finally
	{
		IWTimer1->Enabled= true;
	}
}
<div class="jive-quote">

After some second (on a smartphone connected to internet, not in lan) I receive the "IWTIMER1.DoOnAsyncTimer callback error"
What Im wrong?
Thanks!
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: RealTime data
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 11, 2018 1:31 PM   in response to: Mirco Malagoli in response to: Mirco Malagoli
I don't see anything that you are doing "wrong", but there may a few changes that can make this work better.

1. I modified my example to use a private variable to protect the timer code. My first example was more appropriate for a VCL application. See the code below for the change details.

2. I used a thread-safe version of TimeToStr. The documentation says that the form of the function you used is "not thread-safe, because it uses localization information contained in global variables". You have to be aware of what you are calling in an IW application because everything runs in threads. See the documentation for TimeToStr for more details. There are many system functions that have thread-safe versions.

3. You may have to set the timer interval to something more than 1 second. There may not be enough time to execute your code within that interval. Protecting the code from overrunning itself will help, but you may be generating too much traffic to be processed in a short period of time.

unit Unit1;
 
interface
 
uses
  Classes, SysUtils, IWAppForm, IWApplication, IWColor, IWTypes, Vcl.Controls, IWVCLBaseControl, IWBaseControl, IWBaseHTMLControl, IWControl, IWCompLabel, IWBaseComponent, IWBaseHTMLComponent, IWBaseHTML40Component, IWCompExtCtrls, IWCompButton;
 
type
  TIWForm1 = class(TIWAppForm)
    IWTimer1: TIWTimer;
    IWLabel1: TIWLabel;
    IWButton1: TIWButton;
    procedure IWAppFormCreate(Sender: TObject);
    procedure IWTimer1AsyncTimer(Sender: TObject; EventParams: TStringList);
    procedure IWButton1Click(Sender: TObject);
  private
    ExecutingTimerCode : boolean; //use this to conditionally execute timer code
    formatSettings : TFormatSettings; //required for thread-safe system calls
  public
 
  end;
 
implementation
 
{$R *.dfm}
 
uses ServerController, UserSessionUnit, Windows;
 
procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  ExecutingTimerCode := false;
  GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, formatSettings);
end;
 
procedure TIWForm1.IWButton1Click(Sender: TObject);
begin
  WebApplication.Terminate('Goodbye!');
end;
 
procedure TIWForm1.IWTimer1AsyncTimer(Sender: TObject; EventParams: TStringList);
begin
  if not ExecutingTimerCode then
  begin
    ExecutingTimerCode := true;  //block other executions of this code
    try
      IWLabel1.Caption := TimeToStr(now,formatsettings);  //thread-safe call to TimeToStr
    finally
      ExecutingTimerCode := false; //allow other executions
    end;
  end;
end;
 
initialization
  TIWForm1.SetAsMainForm;
end.
 
Mirco Malagoli

Posts: 4
Registered: 5/13/00
Re: RealTime data
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 22, 2018 7:13 AM   in response to: Mirco Malagoli in response to: Mirco Malagoli
As mentioned in the first post I need to update data in a grid when I have an event from my program.
The test with the timer was the consequence of the fact that I did not see the data updated in the grid.
What is the best way to update the data of all active sessions when I have new data to display (obviously without the need to press F5 on the browser)?

My idea was to use a public method in usersession that updates the data on the page but I have not found any similar approach in any example

Thanks!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02