hola a todos:
tengo un problema con un programa para calcular numeros primos
trabajo con delphi 7.
resulta que el bucle para calcular los numeros primos me consume todo el procesador y queria calcular el tiempo que tarda en completarse con un componente timer que sume uno cada segundo a una variable pero resulta que no empieza a sumar hasta que se acaba el proceso para sacar numeros primos, si pueden ayudarme
gracias
este es el codigo:
Código Delphi
[-]
unit primo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Button1: TButton;
Edit1: TEdit;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
public
end;
var
Form1: TForm1;
numero:longint;
cantidad:longint;
division:longint;
confir:longint;
hora:integer;
minuto:integer;
segundo:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.Enabled := true;
cantidad :=(strtoint(edit1.Text));
numero :=2;
division :=2;
while (numero < cantidad)do
begin
while(division <= numero)do
begin
if numero mod division = 0 then
begin
confir := confir +1;
end;
division := division +1;
end;
division :=2;
if confir =1 then
begin
memo1.Lines.Add(inttostr(numero));
confir := 0;
end
else begin
memo2.Lines.Add(inttostr(numero));
confir :=0;
end;
numero := numero +1;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
segundo := (strtoint(label1.caption)) +1;
label1.caption := (inttostr(segundo));
timer1.Enabled := true;
end;
end.