Procedure

TfrmLabs.Timer1Timer

Module

fLabs

Last Modified

7/15/2014 3:26:38 PM

Visibility

Public/Published

Owner

TfrmLabs

Declaration

procedure Timer1Timer(Sender: TObject);

Calls Hierarchy


TfrmLabs.Timer1Timer
 ├GetRemoteStatus
 ├TfrmLabs.UpdateRemoteStatus
 ├GetRemoteData
 ├TRemoteReportList.Add
 │ └TRemoteReport.Create
 └TfrmLabs.LoadListView
   ├TLabRowObject.Add
   │ ├TCellObject.Create
   │ └TCellObject.Add
   └TUser.HasKey
     └HasSecurityKey

Calls

Name Declaration Comments
TRemoteReportList.Add procedure Add(AReportList, AHandle: string); -
GetRemoteData procedure GetRemoteData(Dest: TStrings; aHandle: string; aItem: PChar); -
GetRemoteStatus function GetRemoteStatus(aHandle: string): String; -
TfrmLabs.LoadListView procedure LoadListView(aReportData: TStringList); -
TfrmLabs.UpdateRemoteStatus procedure UpdateRemoteStatus(aSiteID, aStatus: string); -


Source

3283  procedure TfrmLabs.Timer1Timer(Sender: TObject);
3284  var
3285    i,j,fail,t: integer;
3286    r0: String;
3287  begin
3288    inherited;
3289    t := Timer1.Interval;
3290    with RemoteSites.SiteList do
3291     begin
3292      for i := 0 to Count - 1 do
3293        if TRemoteSite(Items[i]).Selected then
3294         begin
3295          if Length(TRemoteSite(Items[i]).LabRemoteHandle) > 0 then
3296            begin
3297              r0 := GetRemoteStatus(TRemoteSite(Items[i]).LabRemoteHandle);
3298              TRemoteSite(Items[i]).LabQueryStatus := r0; //r0='1^Done' if no errors
3299              UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, piece(r0,'^',2));
3300              if piece(r0,'^',1) = '1' then
3301                begin
3302                  GetRemoteData(TRemoteSite(Items[i]).LabData,
3303                    TRemoteSite(Items[i]).LabRemoteHandle,Items[i]);
3304                  RemoteReports.Add(TRemoteSite(Items[i]).CurrentLabQuery,
3305                    TRemoteSite(Items[i]).LabRemoteHandle);
3306                  TRemoteSite(Items[i]).LabRemoteHandle := '';
3307                  TabControl1.OnChange(nil);
3308                  if (length(piece(uHState,';',2)) > 0) then
3309                    begin
3310                      uRemoteReportData.Clear;
3311                      QuickCopy(TRemoteSite(Items[i]).LabData,uRemoteReportData);
3312                      fail := 0;
3313                      if uRemoteReportData.Count > 0 then
3314                        begin
3315                          if uRemoteReportData[0] = 'Report not available at this time.' then
3316                            begin
3317                              fail := 1;
3318                              UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID,'Report not available');
3319                            end;
3320                          if piece(uRemoteReportData[0],'^',1) = '-1' then
3321                            begin
3322                              fail := 1;
3323                              UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID,'Communication failure');
3324                            end;
3325                          if fail = 0 then
3326                            LoadListView(uRemoteReportData);
3327                        end;
3328                    end;
3329                end
3330              else
3331                begin
3332                  uRemoteCount := uRemoteCount + 1;
3333                  if uRemoteCount > 90 then //~7 minute limit
3334                    begin
3335                      TRemoteSite(Items[i]).LabRemoteHandle := '';
3336                      TRemoteSite(Items[i]).LabQueryStatus := '-1^Timed out';
3337                      UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, 'Timed out');
3338                      StatusText('');
3339                      TabControl1.OnChange(nil);
3340                    end
3341                  else
3342                    StatusText('Retrieving Lab data from '
3343                      + TRemoteSite(Items[i]).SiteName + '...');
3344                end;
3345              if t < 5000 then
3346                begin
3347                  if t < 3001 then Timer1.Interval := 4000
3348                  else if t < 4001 then Timer1.Interval := 5000;
3349                end;
3350            end;
3351         end;
3352       if Timer1.Enabled = True then
3353         begin
3354           j := 0;
3355           for i := 0 to Count -1 do
3356             begin
3357               if Length(TRemoteSite(Items[i]).LabRemoteHandle) > 0 then
3358                 begin
3359                   j := 1;
3360                   break;
3361                 end;
3362             end;
3363           if j = 0 then  //Shutdown timer if all sites have been processed
3364             begin
3365               Timer1.Enabled := False;
3366               StatusText('');
3367             end;
3368           j := 0;
3369           for i := 0 to Count -1 do
3370             if TRemoteSite(Items[i]).Selected = true then
3371               begin
3372                 j := 1;
3373                 break;
3374               end;
3375           if j = 0 then  //Shutdown timer if user has de-selected all sites
3376             begin
3377               Timer1.Enabled := False;
3378               StatusText('');
3379               TabControl1.OnChange(nil);
3380             end;
3381         end;
3382     end;
3383  end;