Autor Beitrag
Black200607
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 50

Win XP
Pascal(Free Pascal/Lazarus), Java, Php, Python
BeitragVerfasst: So 13.01.08 16:16 
Ich will einen Button "springen" lassen. Ich kann ihn bewegen, aber bei meinem Versuch ihn an Wänden apprallen zu lassen bekomme ich Fehlermeldungen.
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:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
unit Uderspringendebutton;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    procedure move (objekt: TButton);
  { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation
  procedure TForm1.move (objekt: TButton);
  var direction: Integer;
  begin
  Timer1.Interval := 330;

    with form1 do
    begin
{richtung waehlen}
    direction := random(4);
    case direction of
    0begin
      repeat
        if (objekt.Top-8 < 0and (objekt.Left-8 < 0then
        begin
         objekt.top := objekt.top-8;
         objekt.left := objekt.left-8;
        end
        else
        begin
{falls Kollision mit der Wand, zu 2}
        direction := 2;
        end;
        until (direction = 2);
        end;
        end;


    1begin
        repeat
        if (objekt.Top+8 > form1.clientheight) and (objekt.Left+8 > form1.clienwidth) then
        begin
         objekt.top := objekt.top+8;
         objekt.left := objekt.left+8;
        end
        else
        begin
        direction := 3;
        end;
        until (direction = 3);
        end;
       end;
    2begin
        repeat
        if (objekt.Top+8 < form1.clientheight) and (objekt.Left-8 > 0then
        begin
         objekt.left := objekt.left-8;
         objekt.top := objekt.top+8;
        end
        else
        begin
        direction := 1;
        end;
        until (direction = 1);
        end;
       end;

    3begin

       repeat
        if (objekt.Top-8 > 0and (objekt.Left+8 < form1.clienwidth) then
        begin
        begin
         objekt.left := objekt.left+8;
         objekt.top := objekt.top-8;
         end;
         end
        else
        begin
        direction := 0;
        end;
        until (direction = 0);
       end;
      end;
     end;
    end;
    end;
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  {start}
 Timer1.Enabled := true;

end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
 Form1.move (Button1);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
{stop}
 Timer1.Enabled := false;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 randomize;
 Timer1.Enabled := false;
end;

end.


Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
Moderiert von user profile iconGausi: Topic aus Sonstiges (Delphi) verschoben am So 13.01.2008 um 16:40
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 13.01.08 16:37 
Hallo,

Kannst du uns vielleicht mal schreiben, wo die Fehler auftreten und wie sie heißen? Dann können wird dir besser helfen.

Grüße
Yogu
Black200607 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 50

Win XP
Pascal(Free Pascal/Lazarus), Java, Php, Python
BeitragVerfasst: So 13.01.08 16:46 
Natürlich:

Bei den Case abschnitten
undefinierter bezeichner 1
undefinierter bezeichner 2
undefinierter bezeichner 3

0 scheint nicht undifiniert zu sein

Dann noch
undefinierter bezeichner objekt, clientwidth,
es sieht aus als währen ALLE weiteren Variablen als undefiniert erklärt
weitere Operatoren Fehler
Der ganze Quelltext ist ein Fehler , Es ist die Rede von Forward und externel dekls
das Punkt hinter dem end wird ignoriert

Weitere aufzuzählen würde sehr sehr lange dauern
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: So 13.01.08 16:52 
Hm also wenn ich mich nicht täusche ist in den Case-Blöcken jeweils ein end; zuviel.
Das sollte zumindest mal die "undefinierter Bezeichner 1/2/3"-Fehler beheben.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 13.01.08 16:55 
Ich weiß nicht, ob das der Fehler ist, aber du greifst praktisch drei mal untereinander geschachtelt auf Form1 zu: Die Methode ist eine von Form1, dann gehtst du mit with Form1 do nochmal in Form1, und dann greifst du mit zum Beispiel form1.clientheight nochmals darauf zu.

Eigentlich kannst du die with-Konstruktion weglassen, und auch das Form1 im oben genannten Source. Vielleicht klappt es dann besser, aber auf jeden Fall wird der Code übersichtlicher.


Zuletzt bearbeitet von Yogu am So 13.01.08 17:26, insgesamt 1-mal bearbeitet
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 13.01.08 16:57 
Mal ein Beispiel was korrekte Formatierung ausmacht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
0:
  begin  
    repeat  
      if (objekt.Top-8 < 0and (objekt.Left-8 < 0then  
      begin  
        objekt.top := objekt.top-8;  
        objekt.left := objekt.left-8;  
      end  
      else  
      begin  
        {falls Kollision mit der Wand, zu 2}  
        direction := 2;  
      end;  
    until (direction = 2);  
  end;  
  end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Black200607 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 50

Win XP
Pascal(Free Pascal/Lazarus), Java, Php, Python
BeitragVerfasst: So 13.01.08 17:05 
ich habe die with-Zeile weggelassen und bei dem 0-Block ein end; ans ende gesetzt
Anstatt der eins will er jetzt ne deklaration
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 13.01.08 17:32 
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:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
unit Uderspringendebutton;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);  
  private  
    procedure move (objekt: TButton);
  { Private-Deklarationen }  
  public  
    { Public-Deklarationen }
  end;  


var  
  Form1: TForm1;  


implementation


{$R *.DFM}

procedure TForm1.move (objekt: TButton);
  var direction: Integer;
  begin
  Timer1.Interval := 330;


    with form1 do
    begin
{richtung waehlen}
    direction := random(4);  
    case direction of
    0begin  
      repeat
        if (objekt.Top-8 < 0and (objekt.Left-8 < 0then  
        begin
         objekt.top := objekt.top-8;  
         objekt.left := objekt.left-8;  
        end
        else  
        begin
{falls Kollision mit der Wand, zu 2}
        direction := 2;  
        end;  
        until (direction = 2);
        end;


 


    1begin
        repeat  
        if (objekt.Top+8 > form1.clientheight) and (objekt.Left+8 > form1.clientwidth) then
        begin  
         objekt.top := objekt.top+8;
         objekt.left := objekt.left+8;
        end  
        else  
        begin
        direction := 3;
        end;  
        until (direction = 3);
        end;

    2begin
        repeat  
        if (objekt.Top+8 < form1.clientheight) and (objekt.Left-8 > 0then  
        begin
         objekt.left := objekt.left-8;  
         objekt.top := objekt.top+8;
        end
        else  
        begin  
        direction := 1;
        end;
        until (direction = 1);  
        end;



    3begin


       repeat
        if (objekt.Top-8 > 0and (objekt.Left+8 < form1.clientwidth) then
        begin
        begin
         objekt.left := objekt.left+8;
         objekt.top := objekt.top-8;
         end;
         end
        else  
        begin  
        direction := 0;  
        end;
        until (direction = 0);  
       end;  
      end;  
     end;
    end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  {start}
 Timer1.Enabled := true;


end;

 
procedure TForm1.Timer1Timer(Sender: TObject);  
begin  
 Form1.move (Button1);  
end;

 
procedure TForm1.Button2Click(Sender: TObject);  
begin  
{stop}
 Timer1.Enabled := false;  
end;  

 
procedure TForm1.FormCreate(Sender: TObject);
begin  
 randomize;  
 Timer1.Enabled := false;  
end;  


end.

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
Black200607 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 50

Win XP
Pascal(Free Pascal/Lazarus), Java, Php, Python
BeitragVerfasst: So 13.01.08 17:38 
Danke, jetzt hat es geklappt. ich habe jetzt jeweils ein end im Quelltext entfernt und den Rechtschreibfehler clien client ausgebessert.