Autor Beitrag
ploRa
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59

Win XP
Delphi 6
BeitragVerfasst: Di 01.02.05 14:24 
Hihoh
wollte mal fragen wie man mit GoTo arbeit und wie man es einsetzt !?

Thx


Moderiert von user profile iconChristian S.: Topic aus Multimedia / Spiele / Grafik verschoben am Di 01.02.2005 um 14:30
ScorpionKing
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Di 01.02.05 14:27 
df-suche ist ganz toll:

Suche in: Delphi-Forum, Delphi-Library GOTO

MfG, Scorpion!

_________________
Aus dem Urlaub zurück!
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 01.02.05 14:28 
Steht alles in der Hilfe und wahrscheinlich sogar mit Beispiel. Aber warum Goto? Delphi ist keine Sprache mehr aus der Steinzeit. Es gibt bessere Möglichkeiten im Programmablauf zu verzweigen.
ploRa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59

Win XP
Delphi 6
BeitragVerfasst: Di 01.02.05 14:28 
hmm habt goto eingeben und da findet er nix :)

sry
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 01.02.05 14:29 
ploRa hat folgendes geschrieben:
... und wie man es einsetzt !?

Am besten gar nicht.
ploRa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59

Win XP
Delphi 6
BeitragVerfasst: Di 01.02.05 14:30 
dann gebt mir ein andere befehl damit ich nicht goto benutzen muss
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Di 01.02.05 14:31 
ploRa hat folgendes geschrieben:
hmm habt goto eingeben und da findet er nix :)

Gut! Dann besteht Hoffnung, dass du es dir gar nicht erst angewöhnst.

Aber im Ernst: Goto ist lang und breit in der Hilfe beschrieben.
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Di 01.02.05 14:35 
ploRa hat folgendes geschrieben:
dann gebt mir ein andere befehl damit ich nicht goto benutzen muss


Gosub :lol:

Du musst dein Programm entsprechend strukturieren, damit du ohne Sprünge auskommst.

Stichworte:
if..then
case..of
while
repeat..until
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 01.02.05 14:39 
ploRa hat folgendes geschrieben:
dann gebt mir ein andere befehl damit ich nicht goto benutzen muss

Du solltest gar nicht so programmieren, dass ein Goto notwendig ist.
Ich programmiere seit fast 25 Jahren und habe es nie benötigt.
Es gibt Schleifen und Bedingungen, die du schick mit Begin-End-Blöcken versehen kannst. Mit Goto verursachst du nur völlig unübersichtlichen Source-Code. Das solltest du dir nicht antun.
Mehr wollte ich dir nicht gesagt haben. Das war als guter Rat gemeint. das es bei dir nicht so angekommen ist, war meine Schuld. Sorry.
Wenn du nicht weißt, wie du deinen Source umschreiben musst, dann zeig mal was davon.
ploRa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59

Win XP
Delphi 6
BeitragVerfasst: Di 01.02.05 14:46 
Joa hier ist was

Also im folgenden Code fallen mehrere Labels herunter und wenn die auf das Image3 treffen sollen die Label.Caption in eine Listbox eingetragen werden !
Und sobald ein Label die 630 erreicht hat soll dieses label wieder von oben anfangen herunterzufallen !!

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:
FOR i:=64 TO 630 DO BEGIN

Label4.top:=i;
if  ((label4.top + label4.height >= image3.top)) and
     (label4.top <= image3.top+image3.height)
    and ((label4.left+label4.width>=image3.left) and
         (label4.left <= image3.left+image3.width))
    then
     label4.Visible:=false;

Label5.Top:=i;
if  ((label5.top + label5.height >= image3.top) and
     (label5.top <= image3.top+image3.height))
    and ((label5.left+label5.width>=image3.left) and
         (label5.left <= image3.left+image3.width))
    then
     label5.Visible:=false;

Label6.top:=i;
if  ((label6.top + label6.height >= image3.top) and
     (label6.top <= image3.top+image3.height))
    and ((label6.left+label6.width>=image3.left) and
         (label6.left <= image3.left+image3.width))
    then
     label6.Visible:=false;

Label7.Top:=i;
if  ((label7.top + label7.height >= image3.top) and
     (label7.top <= image3.top+image3.height))
    and ((label7.left+label7.width>=image3.left) and
         (label7.left <= image3.left+image3.width))
    then
     label7.Visible:=false;

Label8.top:=i;
if  ((label8.top + label8.height >= image3.top) and
     (label8.top <= image3.top+image3.height))
    and ((label8.left+label8.width>=image3.left) and
         (label8.left <= image3.left+image3.width))
    then
     label8.Visible:=false;

Label9.Top:=i;
if  ((label9.top + label9.height >= image3.top) and
     (label9.top <= image3.top+image3.height))
    and ((label9.left+label9.width>=image3.left) and
         (label9.left <= image3.left+image3.width))
    then
     label9.Visible:=false;

Label10.top:=i;
if  ((label10.top + label10.height >= image3.top) and
     (label10.top <= image3.top+image3.height))
    and ((label10.left+label10.width>=image3.left) and
         (label10.left <= image3.left+image3.width))
    then
     label10.Visible:=false;

Label11.Top:=i;
if  ((label11.top + label11.height >= image3.top) and
     (label11.top <= image3.top+image3.height))
    and ((label11.left+label11.width>=image3.left) and
         (label11.left <= image3.left+image3.width))
    then
     label11.Visible:=false;

Label12.top:=i;
if  ((label12.top + label12.height >= image3.top) and
     (label12.top <= image3.top+image3.height))
    and ((label12.left+label12.width>=image3.left) and
         (label12.left <= image3.left+image3.width))
    then
     label12.Visible:=false;

Label13.Top:=i;
if  ((label13.top + label13.height >= image3.top) and
     (label13.top <= image3.top+image3.height))
    and ((label13.left+label13.width>=image3.left) and
         (label13.left <= image3.left+image3.width))
    then
     label13.Visible:=false;

{Label14.top:=i;
Label15.Top:=i;
Label16.top:=i;
Label17.Top:=i;}

Delay(60);


Ich weiß das man alles bestimmt einfach schreiben kann aber ich kann es halt nicht so wirklich !

Hier ist der Code wo ich etwas in die Labels vorher reinschreibe

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:
// 1 Zufall
randomize;
zufall[0]:=random(form1.listbox2.items.count);
laenge[0]:=length(form1.listbox2.items[zufall[0]]);
position[0]:= pos('-',form1.listbox2.items[zufall[0]]);

silbe[0]:=leftstr(form1.listbox2.items[zufall[0]],position[0]-1);
Label4.Caption:=silbe[0];
silbe[1]:= midstr(form1.listbox2.items[zufall[0]],position[0]+1,laenge[0]);
Label5.Caption:=silbe[1];


// 2 Zufall
zufall[1]:=random(form1.listbox2.items.count);
laenge[1]:=length(form1.listbox2.items[zufall[1]]);
position[1]:= pos('-',form1.listbox2.items[zufall[1]]);

silbe[2]:=leftstr(form1.listbox2.items[zufall[1]],position[1]-1);
Label6.Caption:=silbe[2];
silbe[3]:= midstr(form1.listbox2.items[zufall[1]],position[1]+1,laenge[1]);
Label7.Caption:=silbe[3];


// 3 Zufall
zufall[3]:=random(form1.listbox2.items.count);
laenge[3]:=length(form1.listbox2.items[zufall[3]]);
position[3]:= pos('-',form1.listbox2.items[zufall[3]]);

silbe[6]:=leftstr(form1.listbox2.items[zufall[3]],position[3]-1);
Label8.Caption:=silbe[6];
silbe[7]:= midstr(form1.listbox2.items[zufall[3]],position[3]+1,laenge[3]);
Label9.Caption:=silbe[7];


// 4 Zufall
zufall[2]:=random(form1.listbox2.items.count);
laenge[2]:=length(form1.listbox2.items[zufall[2]]);
position[2]:= pos('-',form1.listbox2.items[zufall[2]]);

silbe[4]:=leftstr(form1.listbox2.items[zufall[2]],position[2]-1);
Label10.Caption:=silbe[4];
silbe[5]:= midstr(form1.listbox2.items[zufall[2]],position[2]+1,laenge[2]);
Label11.Caption:=silbe[5];


// 5 Zufall
zufall[4]:=random(form1.listbox2.items.count);
laenge[4]:=length(form1.listbox2.items[zufall[4]]);
position[4]:= pos('-',form1.listbox2.items[zufall[4]]);

silbe[8]:=leftstr(form1.listbox2.items[zufall[4]],position[4]-1);
Label12.Caption:=silbe[8];
silbe[9]:= midstr(form1.listbox2.items[zufall[4]],position[4]+1,laenge[4]);
Label13.Caption:=silbe[9];


Die Wörter nehme ich aus einer Listbox wo sie folgendermaßen aufgelistet sind:

Vor-name
Straßen-schild

Ich hoffe ihr könnt damit was anfangen


Zuletzt bearbeitet von ploRa am Di 01.02.05 14:48, insgesamt 1-mal bearbeitet
I.MacLeod
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 109



BeitragVerfasst: Di 01.02.05 14:47 
Mir fallen zwei Gründe ein warum man es benutzen kann:

1. Sprung aus zwei Schleifen gleichzeitig. Der Umweg über eine extravariable bei while- & repeat-Schleifen könnte noch unübersichtlicher sein, bei for geht es nicht anders und schneller ist es sowieso.

2. Manchmal lässt sich damit Code optimieren, allerdings wird es wenn man so weit gekommen ist vermutlich sehr eklig :roll:

also: Hör auf jasocul, es sei denn (1) trifft zu ;]

_________________
{$APPTYPE CONSOLE}uses SysUtils;const a='{$APPTYPE CONSOLE}uses SysUtils;const a=%s;begin write(Format(a,[#39+a+#39]))end.';begin write(Format(a,[#39+a+#39]))end.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 01.02.05 14:59 
@ploRa:
Schreib doch noch eben, wofür du ein goto haben willst und wo. Mir wird der Zusammenhang deines Programmes so nicht klar.

@I.MacLeod:
Wenns unübersichtlich wird, hilft es Prozeduren zu schreiben :wink:
Notfalls kann man noch Exit oder Break verwenden. Break habe ich einmal verwendet, weil ich zu faul war eine eine Schleife umzuprogrammieren. :oops:
Exit benutze ich manchmal zum Testen von Routinen. Wenn diese nicht laufen, schreibe ich ganz oben exit rein.
ploRa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59

Win XP
Delphi 6
BeitragVerfasst: Di 01.02.05 15:08 
Ehm Also ich habe in einer Listbox mehrer Wört wie folgt stehen:
Das wird ein Lernspiel für die 6 Klasse

Vor-name
Straßen-schild
Straßen-rand
Nach-name
etc.

Diese Wörter werden in verschieden labels verteilt zB.

Label1 = Vor
label2 = name
Label3 = Starßen
Label4 = schild
etc.

Diese Labels fallen jetzt von oben herab und die Schüller müssen mit einem Image die Labels einfangen !
Natrürlich so, dass die Wörter wieder richtig zusammen gesetzt werden. Deswegen Lernspiel^^ !

Wenn die Schüler nun ein Label aufgefangen haben, soll der Inhalt des Labels ( Caption ) in eine Neue sichtbare Listbox1 reingeschrieben werden am besten wieder mit folgender strucktur:

Vor-Name
etc.

Je nachdem wie sie die Wörter auffangen kann es auch passieren, dass sowas drin stehen soll:

Vor-schild
etc.

Und es fallen ca. 8 Labels auf einmal die Form herunter wenn eins unten angekommen ist, soll es wieder von oben beginnen mit einem neuem Wort aus meiner Listbox !

Brauchst du das ganze Programm ?
Oder reicht dir der teil des Code´s ?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 01.02.05 15:13 
1. Das Programm klingt interessant. Kann ich es bekommen, wenn es fertig ist?
2. Eigentlich wollte ich wissen, unter welchen Umständen du eine goto benötigst.
ploRa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59

Win XP
Delphi 6
BeitragVerfasst: Di 01.02.05 15:15 
klar kannst du es dann bekommen

Ich brauche ein goto ( habe ich mir so gedacht )
weil in moment die labels nur herunterfallen und nciht wieder von oben neu anfangen herunterzufallen.. deshalb wollte ich ein goto machen
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 01.02.05 15:23 
Im Source hast du z.B. :
ausblenden Delphi-Quelltext
1:
label4.Visible := False;					

Schreibe doch stattdessen die Startposition des Labels wieder in Left und Top. Dann sollte das doch von vorne anfangen.