Autor Beitrag
Black Force
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mi 05.12.07 16:09 
Hallo, :D

Ich hab ein kleines Problem. Ich habe ein Programm geschrieben indem sich ein Objekt auf dem Formular von einem Punkt zum anderen bewegt.
Das Objekt soll z.B. verschwinden, wenn ich drauf klicke.
Aber das tut es erst, wenn es sein Ziel erreicht hat. Wie kann ich machen, dass er auch mitten auf dem Weg verschwinden kann?

So habe ich die Bewegung dargestellt:

ausblenden 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:
if Image1.Left < x then
  repeat
  Image1.Left := Image1.Left + 1;
  repaint; sleep(10);
  until
  Image1.Left >= x
  else if Image1.Left > x then
  repeat
  Image1.Left := Image1.Left - 1;
  repaint; sleep(10);
  until
  Image1.Left <= x;

  if Image1.top < y then
  repeat
  Image1.top := Image1.top + 1;
  repaint; sleep(10);
  until
  Image1.top >= y
  else if Image1.top > y then
  repeat
  Image1.top := Image1.top - 1;
  repaint; sleep(10);
  until
  Image1.top <= y;
  end;


Hoffe ihr könnt mir helfen

Moderiert von user profile iconTino: Highlight- durch Delphi-Tags ersetzt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 05.12.07 16:26 
Sehr einfach: Benutze nicht sleep ;-), das hält ja explizit deine Anwendung (bzw. deren Hauptthread) an.
Nimm stattdessen Application.ProcessMessages und GetTickCount:
www.delphipraxis.net/post173711.html
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mi 05.12.07 16:34 
danke für die antwort.
Ich guck mir das mal an.dann meld ich mich.
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mi 05.12.07 16:53 
application.processmessages hab ich einigermaßen gecheckt.
Funktioniert auch fast einwandfrei. Bloß ich hab immer noch sleep() drin.
Ich weiß nicht wie ich gettickcount benutzen soll. Hab auch in der Delphi Hilfe nachgeschlagen.
Wie kann ich es in meinem Fall benutzen?
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 05.12.07 16:57 
So:
user profile iconjaenicke hat folgendes geschrieben:
www.delphipraxis.net/post173711.html

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."