Now that we have done that, we can finish filling the table by generating primes by a brute force trial and error method. The modulo function does this nicely since, by definition, n mod m is the remainder when n is divided by m. All of this initialization is done in as the program starts in the Create constructor method of a TPrimes object. TObject in this case. An instance of TPrimes , named Primes , is created in the Initialization section of the unit.
Downloaded source has both units.
Explorations TPrimes originally included a GetPrevPrime function. I removed it since I hadn't had a chance to test it. The most straightforward way is to successively subtract 1 from the input number and call IsPrime until it returns true. The displays of large numbers would be easier to read if they were formatted with commas. Intellitech Systems Inc. All rights reserved.