Autor Beitrag
GR-Thunderstorm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: Di 09.05.06 20:02 
Ich will in eine Schleife eine Verzögerung einbauen. Die Schleife dient dem Zweck, ein Bild zu bewegen.

Der Teil mit der Schleife zur Bewegung sieht soweit so aus:

for i:= 1 to 10 do
begin
image1.left:=image1.left+1;
end;


Wie bekomm ich es hin, dass Delphi eine kurze Zeit wartet, bevor es i weiter erhöht und das Bild somit weiterbewegt?

Wieso funktioniert der aus Pascal bekannte befehl delay(100); nicht in Delphi?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 09.05.06 20:09 
Moin und :welcome: im Forum!

Du kannst vermutlich besser mit GetTickCount arbeiten, einfach das Wort eingeben und F1 drücken. ;)

Ansonsten: die Suchfunktion Suche in: Delphi-Forum, Delphi-Library DELAY SLEEP

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
fidionael
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Di 09.05.06 20:09 
Delay gibt es nicht mehr auf Grund des nun etablierten Multi-Tasking :-)

Das Äquivalent ist
ausblenden Delphi-Quelltext
1:
sleep(Zeit_in_ms);					
starsurfer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 334

Win 95, Win 98, Win XP, Win Vista, Linux
D5 Enterprise ,D2005, D6 Personal, Visual C++ Express 2005, C++ Builder 6 E, Dev-C++
BeitragVerfasst: Di 09.05.06 20:10 
dafür gibt es jetzt sleep(100).
Davon ist aber abzuraten weil das Programm dann einfriert, nehm lieber:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
image1.left:=image1.left+1
end;

_________________
GEIZ IST GEIL! - Ihr Sozialamt
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 09.05.06 20:47 
Um auf den Titel des Threads zurückzukommen: Es geht auch mit nem Timer. Ins OnTimer.Event kommt dann:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
// Damits irgendwann stoppt
if Timer1.Tag = 10 then Timer1.enabled := false;
// Bild verschieben
image1.left:=image1.left+1;
// tag erhöhen
Timer1.Tag := Timer1.Tag + 1;


Gestartet wird das dann z.B. mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
// Tag zurücksetzen
timer1. Tag := 0;
// timer starten
timer1.enabled := True;

_________________
We are, we were and will not be.
GR-Thunderstorm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: Di 09.05.06 21:59 
Das sieht ziemlich kompliziert aus... :?!?:

Das Problem ist, ich habe 4 verschiedene Schleifen. Ums auch für euch übersichtlich zu halten schreib ich die wichtigsten Punkte mal auf:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
begin

 if key = 'd' then
 begin
   for i:=1 to 10 do
     begin
     image1.left:=image1.left+1;
     end;
 end;

 if key = 'a' then
 begin
   for i:=1 to 10 do
     begin
     image1.left:=image1.left-1;
     end;
 end;

 if key = 'w' then
 begin
   for i:=1 to 10 do
     begin
     image1.top:=image1.top-1;
     end;
 end;

 if key = 's' then
 begin
   for i:=1 to 10 do
     begin
     image1.top:=image1.top+1;
     end;
 end;

end;


Ich möchte nicht, dass sich mein Bild so ruckhaft immer gleich um 10 Pixel verschiebt, es soll ganz geschmeidig in 10-Pixel-Abständen über den Bildschirm gleiten...

Moderiert von user profile iconGausi: I- durch Delphi-Tags ersetzt. Um es noch ein bißchen übersichtlicher zu machen ;-)
fidionael
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Di 09.05.06 22:32 
Ich sehe jetzt allerdings nicht so richtig dein Problem dabei - du kannst es doch immer noch alles in eine Timer-Prozedur stecken und wenn du je Timer-Aufruf um 1px verschiebst, bei einem Interval von ca 20-30ms sollte eine flüssige Animation entstehen.

Mfg
GR-Thunderstorm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: Mi 10.05.06 11:51 
Ich hab das ganze jetzt ohne Timer hinbekommen.
Trotzdem danke an euch! :)
DaKirsche
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
BeitragVerfasst: Mi 10.05.06 12:35 
Mit Timer :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Tag := Timer1.Tag +1;
  if (Timer1.Tag = 10then
    begin
      Image1.Left := Image1.Left -1;
      Timer1.Tag := 0;
    end;
end;


Ohne Timer :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button1Click(Sender: TObject);
var Ticker : integer;
begin
Form1.DoubleBuffered := True;
 repeat
    Ticker := 0;
    Image1.Left := Image1.Left -1;
   repeat
      Ticker := Ticker + 1;
      sleep(10);
      Application.Processmessages;
   until (Ticker > 2);
    Application.Processmessages;
  until (Image1.Left <= 5);
end;


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt