Thema: Delphi delay problem!

Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#21
  Alt 17. Mär 2003, 15:09
Schon mal an einen Timer gedacht?

Geht wunderbar:
Delphi-Quellcode:
procedure delay(msec:longint);
var
  start,stop:longint;
begin
  start := gettickcount;
  repeat
    stop := gettickcount;
    application.processmessages;
  until (stop - start ) >= msec;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i : Integer;
begin
  for i := 0 to 60 do
  begin
    Application.ProcessMessages;
    Label1.Caption := IntToStr(i);
    Delay(1000);
  end;
end;
Bzw. so wie du es willst:
Delphi-Quellcode:
procedure delay(msec:longint);
var
  start,stop:longint;
begin
  start := gettickcount;
  repeat
    stop := gettickcount;
    application.processmessages;
  until (stop - start ) >= msec;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i, calc : Integer;
begin
  calc := 61;
  for i := 0 to 60 do
  begin
    Application.ProcessMessages;
    Dec(calc);
    Label1.Caption := IntToStr(calc);
    Delay(1000);
  end;
end;
Oder so:
Delphi-Quellcode:
procedure delay(msec:longint);
var
  start,stop:longint;
begin
  start := gettickcount;
  repeat
    stop := gettickcount;
    application.processmessages;
  until (stop - start ) >= msec;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i : Integer;
begin
  for i := 60 downto 0 do
  begin
    Application.ProcessMessages;
    Label1.Caption := IntToStr(i);
    Delay(1000);
  end;
end;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat