Autor Beitrag
n-regen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 202
Erhaltene Danke: 2



BeitragVerfasst: Mo 24.07.06 17:00 
Hallo!
Gibt es in Delphi eine Möglichkeit, wie man eine bestimmte Zeitspanne warten kann, ohne das Programm währenddessen zu freezen?
Fighter#1
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 787

Win XP, Ubuntu 8.04
Turbo Delphi 2006, Delphi 2005 Pe, Delphi 5 Pe, Netbeans 6.1, Eclipse, Microsoft VisualC#, Dev C++, PHP, HTML, CSS
BeitragVerfasst: Mo 24.07.06 17:03 
es gibt natürlich noch den Timer, aber der is eher nicht so genau.

_________________
Wer andere beherrscht ist stark,
wer sich selbst beherrscht ist mächtig. Lao Tse
n-regen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 202
Erhaltene Danke: 2



BeitragVerfasst: Mo 24.07.06 17:08 
Das is das Problem:
ich will das in den quelltext:
ausblenden Delphi-Quelltext
1:
2:
3:
blablabla
warte(1000)
laberlaber
Grendel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 443

Gentoo Linux, MacOS X, Win 2000
D5 Ent, D7 Ent, Lazarus, Anjuta, MonoDevelop
BeitragVerfasst: Mo 24.07.06 17:27 
user profile iconn-regen hat folgendes geschrieben:
[...] warten kann, ohne [...] freezen?

Nein, denn entweder wartet dein Programm, oder es "freezed" (manmanman...) nicht.
Du hast zwei Möglichkeiten. Entweder du arbeitest mit Threads oder aber einem solchen Konstrukt (ungestestet):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure Warte(AMilliSeconds: Integer);
var
  i: Integer;
begin
  while i < AMilliSeconds do
  begin
    sleep(100);
    Application.ProcessMessages();
    Inc(i, 100);
  end;
end;


Allerdings werden während dieses "Wartens" (genauer bei Application.ProcessMessages()) auch Benutzereingaben (Klick auf Abbrechen, Schließen, etc.) verarbeitet.

Bis neulich ...
n-regen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 202
Erhaltene Danke: 2



BeitragVerfasst: Mo 24.07.06 17:31 
Hurra!
Das ist genau das, was ich brauche: das Programm arbeitet beim Warten weiter.
Fighter#1
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 787

Win XP, Ubuntu 8.04
Turbo Delphi 2006, Delphi 2005 Pe, Delphi 5 Pe, Netbeans 6.1, Eclipse, Microsoft VisualC#, Dev C++, PHP, HTML, CSS
BeitragVerfasst: Mo 24.07.06 18:17 
Wobei nachher die Zeit auch nicht ganz stimmt.

_________________
Wer andere beherrscht ist stark,
wer sich selbst beherrscht ist mächtig. Lao Tse
n-regen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 202
Erhaltene Danke: 2



BeitragVerfasst: Di 25.07.06 09:33 
Es geht ja bloß um Sekunden - keine Milli-Sekunden!
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 25.07.06 09:47 
Ich denke, das hilft weiter:

www.delphi-library.d...chonender_23225.html

_________________
We are, we were and will not be.
n-regen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 202
Erhaltene Danke: 2



BeitragVerfasst: Di 25.07.06 09:56 
Ich habs doch schon:

user profile iconGrendel hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure Warte(AMilliSeconds: Integer);
var
  i: Integer;
begin
  while i < AMilliSeconds do
  begin
    sleep(100);
    Application.ProcessMessages();
    Inc(i, 100);
  end;
end;

Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Di 25.07.06 10:20 
Warum soll Sleep genauer als ein Timer sein? Ein Timer wäre doch genau das richtige oder eben ein Thread...
EDIT: Ach du benutzt ja immer noch Sleep.. naja alle 100ms Application.ProcessMessages ist ja auch nicht das wahre


greetz

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Di 25.07.06 10:57 
user profile iconn-regen hat folgendes geschrieben:
Ich habs doch schon

Ja, aber das was du hier machst ist ein so genanntes "Polling". Du fragst in einer Schleife immer wieder eine bestimmte Bedingung ab, und machst in der Zwischenzeit nichts anderes als darauf zu warten, dass diese auftritt (und fragst weiter ab). Dies belastet die CPU ganz schön (auch wenn das in deinem Fall durch das sleep halbwegs relativiert wird).
In dem Link den Gausi schon gepostet hat (www.delphi-library.d...honender_23225.html) zeig ich eine Methode die dasselbe macht wie deine, dabei aber wesentlich resourcenschonender ist...

Gruß, Motzi

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!