Einzelnen Beitrag anzeigen

davtix

Registriert seit: 29. Mai 2003
Ort: Berlin
87 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

For Schleife zählt mehr als vorhanden. iTask, for Schleife, integer -> fehler

  Alt 21. Jun 2021, 16:57
For Schleife zählt mehr als vorhanden. iTask, for Schleife, integer -> fehler.

im folgenden Bsp. zählt die (var THI :integer) mehr als angegeben und lässt eine Zählung aus.
Also THI = 0,1,2,3,4,5,6,7,8,9,10,12 <<
Ich dachte hier überschneidet sich irgendwas und wollte dies mit tempTHI := THI; //thi integer für task separieren. doch auch hier wird die 11 ausgelassen und mit 12 weitergemacht.

- Wieso zählt hier ein festes integer Array weiter als angegeben ?
- continue hab ich hier ausgesetzt , ohne erfolg



Delphi-Quellcode:

  TTasks = Array [0..11] of ITask;
  TTaskActiveArray = Array [0..11] of integer;
var
  Tasks:TTasks;
  TaskActiveAr:TTaskActiveArray;


Delphi-Quellcode:
var THI:integer;


anyTaskIsRunning := 1;
for THI := 0 to 11 do
    begin
      log(1,'read_ALL_data->TaskActiveAr['+ inttostr(THI) +'] = ' + inttostr( TaskActiveAr[THI] ) + ' begin');

      //thread erstellen
      Tasks[THI] := TTask.Create( procedure () var indI, tempTHI, is_own_number, byte : integer; tempS, tempS1, tempS2, tempS3, tempS4:string;
        begin
          tempTHI := THI; //thi integer für task separieren
          //task I/O ob task running (0 fetrig, 1 running, 2 soll, 3 nicht gebraucht)
          TaskActiveAr[tempTHI] := 1; log(7,'read_ALL_data->TASK TaskActiveAr['+ inttostr(tempTHI) +'] = ' + inttostr( TaskActiveAr[tempTHI] ) + ' begin');
          log(0,'tempTHI / THI = ' + inttostr( tempTHI ) + ' / ' + inttostr( THI ) );


          //thread geht komplette liste durch und bearbeitet nur seine threadnummer
          for indI := 0 to box.RowCount - 1 do
            begin
              tempI := -1; is_own_number := 0;
              //threadnummer auslesen und in integer wandeln wenn möglich
              if ( true = IsStringAInteger( box.Cells[ 9, indI] )) then
                begin
                  tempI := strtoint(box.Cells[ 9, indI]); //log(0,'IsStringAInteger --> line('+ inttostr( indI ) +') = tempI : ' + inttostr( tempI ) );
                end else
                begin
                  //log(0,'line (' + inttostr( tempI ) + ') IsStringAInteger -> line('+ inttostr( indI ) +') = false --> continue ');
                  //wenn kein integer dann überspringe
                  //continue;
                end;

              //prüfen ob eigene threadnummer
              if ( tempI = tempTHI ) then
                begin
                  is_own_number := 1; // log(0,'is_own_number --> line('+ inttostr( indI ) +') = tempI : ' + inttostr( tempI ) + ' == tempTHI: ' + inttostr( tempTHI ) );
                end else
                begin
                  //log(0,'is_own_number -->FALSE line('+ inttostr( indI ) +') = tempI : ' + inttostr( tempI ) + ' == tempTHI: ' + inttostr( tempTHI ) );
                  //wenn nicht dann überspringe
                  //continue;
                end;

              if (is_own_number = 1) then
                begin
                  tempS:= ''; tempS1 := ''; tempS2:= ''; tempS3:= ''; tempS4 := '';
                  //kompletten pfad einlesen
                  tempS := box.Cells[ 7, indI];

                  tempS1 :='';
                  if ( FileExists( tempS ) ) then
                    begin
                      byte := GetFileSize( tempS );
                      tempS1 := konvertBytes( byte );
                      delay(100);
                    end;

                  tempS2 :='';
                  tempS2 := DateTimeToStr( GetCreationTimeOfFile( tempS )); //erstellt

                  tempS3 :='';
                  tempS3 := DateTimeToStr( GetFileLastAccessTime( tempS )); //letzter zugriff

                  tempS4 :='';
                  tempS4 := DateTimeToStr( GetFileDate( tempS )); //geändert

                end;


              if (is_own_number = 1) then
                begin
                  box.Cells[2,indI] := tempS1; //dateigrösse

                  box.Cells[3,indI] := tempS2; //erstellt

                  box.Cells[4,indI] := tempS3; //letzter zugriff

                  box.Cells[5,indI] := tempS4; //geändert

                end;

            end; //thread geht komplette liste durch und bearbeitet nur seine threadnummer --> end

              TThread.Synchronize(nil,procedure ()
                begin

                end);


          //task I/O ob task running (0 fetrig, 1 running, 2 soll, 3 nicht gebraucht)
          TaskActiveAr[ tempTHI ] := 0; log(7,'read_ALL_data->TaskActiveAr['+ inttostr(tempTHI) +'] = ' + inttostr( TaskActiveAr[tempTHI] ) + ' end');
        end);
      Tasks[THI].Start;

      delay(100);
      //if ( THI = 11 ) then anyTaskIsRunning := 0;
    end;

Geändert von davtix (21. Jun 2021 um 17:20 Uhr)
  Mit Zitat antworten Zitat