Autor Beitrag
-Nala-
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62



BeitragVerfasst: Sa 27.01.07 16:21 
hey leute !!
habe bisjetzt noch keinen anfängerthread gefunden
deshalb hab ich einfach einen gemacht.
also ich hab ne frage :
Ich hab jezt ungefähr seit ner woche delphi 5 und
ich möchte ein image von a nach b wandern lassen und dann soll es apprallen
mein lehrer hat gesagt dass das irgendwie mit
if.... then geht aber ich kapier das einfach nich!
könnt ihr mir helfen ?????

THX


Moderiert von user profile iconGausi: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Sa 27.01.2007 um 16:37


Zuletzt bearbeitet von -Nala- am Sa 27.01.07 16:33, insgesamt 1-mal bearbeitet
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: Sa 27.01.07 16:32 
Wir trennen hier nicht zwischen Anfängerfragen und anderen Fragen ;-). Da gibts also keinen besonderen Thread für, das ist schon richtig, wenn du einfach einen neuen für jede Frage machst.

Zu deiner Frage: Die Frage kommt mir ziemlich bekannt vor.
Wie wärs z.B. mit diesem Thema:
www.delphi-forum.de/...68479&highlight=
Und irgendwo war so eine a nach b Frage auch noch in den letzten Tagen, aber die finde ich grad nicht...
-Nala- Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62



BeitragVerfasst: Sa 27.01.07 16:52 
Hi ...
ich bins nochma
also..
ich hab das so programiert wies auf dem link
stand aber es funktioniert nich könnt ihr mir sagen was daran falsch is ?
THX

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:
36:
37:
38:
39:
40:
41:
42:
43:
44:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    ImReagenzglas: TImage;
    ImNa1: TImage;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
ImNa1.canvas.ellipse(0,0,30,30);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
ImNa1.Top:=ImNa1.top+5;
ImNa1.left:=ImNa1.left-9;
If ImNa1.left>370
Then
begin
ImNa1.left:=-ImNa1.left;
end;

end


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
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: Sa 27.01.07 16:55 
Was funktioniert denn nicht?
Das musst du schon dazu sagen...
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 27.01.07 16:57 
Du brauchst auf der Form einen Timer, der du das Timer-Event zuordnest. Außerdem noch ein TImage mit Namen "ImNa1". Dann funktioniert es.

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



BeitragVerfasst: Sa 27.01.07 16:57 
also der sagt immer
das unter dem letzten end was fehlt also der makiert ne leere zeile
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: Sa 27.01.07 16:59 
Nein, ich glaube da fehlt noch ein end...
Vorausgesetzt die Datei ist da zuende, muss es so sein:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Timer1Timer(Sender: TObject); 
begin 
  ImNa1.Top := ImNa1.Top + 5; 
  ImNa1.Left := ImNa1.Left - 9; 
  if ImNa1.Left > 370 then 
  begin 
    ImNa1.Left := -ImNa1.Left; 
  end; 
end;

end.


// EDIT: Richtig geraten...
// EDIT2:
@user profile icon-Nala-: Und hättest du es korrekt eingerückt, dann hättest du das auch gemerkt... :twisted:
-Nala- Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62



BeitragVerfasst: Sa 27.01.07 17:01 
kannst du mir vllt
sagen was ich wohin schreiben muss oder was ich in meinen frame ziehen soll ??
ich hab delphi erst seit ner woche und muss ne animation programmieren
THX
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: Sa 27.01.07 17:04 
Was meinst du? Da fehlte doch nur die Zeile, die ich bei mir gehighlightet habe. Aber meine Antwort hast du bei deiner Antwort vermutlich noch gar nicht gesehen, oder? ;-)
-Nala- Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62



BeitragVerfasst: Sa 27.01.07 17:05 
ok jeztz zeigt er keine fehlermeldung
mehr an aber die ellipse versch´windet einfach ?????????
könnt ihr mir vllt nochma helfen???????
THX
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: Sa 27.01.07 17:17 
Sieh dir mal dieses Beispiel an, ich meinte eher das in dem verlinkten Thread als das, was der Fragesteller dort selbst geschrieben hat. Das hat ja schließlich nicht funktioniert. ;-)
www.delphi-forum.de/...&start=20#412937

Warum die Ellipse verschwindet ist relativ einfach: Left wird immer kleiner, das Abprallen wird aber bei > 370 aktiv und dann leider nicht korrekt.
Richtig wäre sowas:
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:
27:
28:
var
  Form1: TForm1;
  RichtungNachRechts: Boolean = True;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  ImNa1.Canvas.Ellipse(0, 0, 30, 30);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  ImNa1.Top := ImNa1.Top + 1;
  if RichtungNachRechts and (ImNa1.Left + ImNa1.Width < Width) then
    ImNa1.Left := ImNa1.Left + 4
  else if ImNa1.Left + ImNa1.Width >= Width then
  begin
    RichtungNachRechts := False;
    ImNa1.Left := ImNa1.Left - 4;
  end
  else if ImNa1.Left > 0 then
    ImNa1.Left := ImNa1.Left - 4
  else
    RichtungNachRechts := True;
end;

Das unten abprallen fehlt da noch.
-Nala- Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62



BeitragVerfasst: Sa 27.01.07 17:29 
DANKE !!!!!!
Das hat mir wirklich sehr weiter geholfen nur ich muss das jeztz
noch so programmieren, dass das image auch unten und oben abprallt
kann du mia bitte noch ma helfen????
THX
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: Sa 27.01.07 17:32 
Naja, eas ist ja genau dasselbe wie rechts und links... :roll:
Mach dir halt ne Variable für Richtung nach unten und dann musst du das mit Top (und Height) ja nur noch so machen wie ich es mit Left (und Width) gemacht habe.
-Nala- Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62



BeitragVerfasst: Sa 27.01.07 17:44 
also ich hab deinen rat befolgt unddann war irgendwas falsch in pas 45,46,53,55 und dpr 5

hier is die unit könnt ihr mir sagen was falsch is ?????
THX

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:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    ImReagenzglas: TImage;
    ImNa1: TImage;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;  
  RichtungNachRechts: Boolean = True;
  n:Boolean = True;

 
implementation


{$R *.dfm}  

 
procedure TForm1.FormCreate(Sender: TObject);
begin  
  ImNa1.Canvas.Ellipse(0, 0, 30, 30);  
end;  

 
procedure TForm1.Timer1Timer(Sender: TObject);  
begin  
  ImNa1.Top := ImNa1.Top + 1;
  if RichtungNachRechts and n and (ImNa1.Left + ImNa1.Width < Width) and (ImNa1.Top + ImNa1.Height < Height) then
    ImNa1.Left := ImNa1.Left + 4
    ImNa1.top := ImNa1.top-4
  else if ImNa1.Left + ImNa1.Width >= Width and ImNa1.Top + ImNa1.Height >= Height then
  begin  
    RichtungNachRechts := False;  
    ImNa1.Left := ImNa1.Left - 4;
    n := false;
    ImNa1.top := ImNa1.top +4;
  end
  else if ImNa1.Left > 0 and ImNa1.top > 0 then
    ImNa1.Left := ImNa1.Left - 4
    ImNa1.top := ImNa1.top +4
  else
    RichtungNachRechts := True;
    n := true;
end; 

end.


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
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: Sa 27.01.07 17:51 
Ich hab jetzt nicht im Detail nachgesehen, aber es gehört immer nur der nächste Befehl zu if. Soll mehr als ein Befehl dort ausgeführt werden, musst du begin..end benutzen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
if Bedingung then
  EinBefehl
else
  NochEinBefehl;

if Bedingung then
begin
  EinBefehl;
  NochEinBefehl;
end
else
begin
  NochEinBefehl;
  UndNochEiner;
end;

Aber hier brauchst du das doch gar nicht. Du solltest vielleicht mal erstmal den Quelltext verstehen! Wenn du den nicht verstehst, dann frag bitte!
Du musst statt mit ImNa1.Top := ImNa1.Top + 1; das Bild immer ein Pixel nach unten zu schieben, dieses ggf. auch nach oben schieben.
Du musst also statt dieser Zeile nochmal das machen, was ich darunter mit Left und Width gemacht habe...