Unless you declare a variable to hold the return value of TCheck.Create
, you cannot access TCheck.Start
(there is no instance of TCheck
that you can use to access the Start
method).
The correct way would be to declare var Check: TCheck;
inside MainT.Execute
, and then save the return value:
Check := TCheck.Create(Load[i]); { See note below } Check.Start; Inc(tCount);
NOTE The default property of TStringList
is Strings
, so you do not need to use it. You can simply access Strings
directly, as I said above. The following two lines are the same thing (but obviously one of them is shorter and easier to type):
Load.Strings[i]; Load[i];
If you do not want to keep a link to TCheck
, just change your code as a with
block (including begin..end
and not containing other code in the block (this is only the way I recommend using with
):
with TCheck.Create(Load[i]) do begin Start; Inc(tCount); end;
With that said, there are much better ways to do this, instead of creating / destroying all kinds of threads. As others have said, you can have a list of 10 threads and a work queue for them, so that everyone will process an element from Load
, and then return to get another element to process when this is done, and repeat until the list completed, It's hard to say exactly how you do it, because it will depend on your version of Delphi. (Libraries are available that will do most of the work for you, such as OMNIThreadLibrary
, but it is not available for some older versions of Delphi. Recent versions of Delphi also support TQueue
and TObjectQueue
, as well as some other types and functions that can be very useful.
(If you have another question about how to do this in a queue with a limited number of threads, this should be a new question , not what you add to this.)