Autor Beitrag
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.11.17 18:14 
user profile iconSymbroson hat folgendes geschrieben Zum zitierten Posting springen:
darf ich nochmal dazwischengrätschen ;)
Ehrlich gesagt: nein. :| Das stört grade etwas. :?

@Lena: Die Hinweise von Symbroson sind sicher korrekt, aber z.Zt. nicht wichtig oder relevant. Ich würde dir empfehlen, den Beitrag erstmal zu ignorieren. Wir sollten die Listbox jetzt wieder richtig ans Laufen kriegen.

_________________
There are 10 types of people - those who understand binary and those who don´t.
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 18:23 
funktioniert ganz normal ohne Fehler wenn ich die Liste lösche und die Anweisung kommentiere
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.11.17 18:25 
Gut, dann wieder eine neue Listbox auf das Formular legen, .Sorted auf TRUE stellen, den Code im Button-Handler wieder aktivieren und neu probieren. Sind die Zahlen jetzt (ja, aufsteigend) sortiert? :lupe:

_________________
There are 10 types of people - those who understand binary and those who don´t.
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 18:27 
oh man, ich habe meinen Fehler gefunden!
Die liste nimmt ein selbst geschriebenes true im Objektinspektor nicht an, man muss es mit der Maus auswählen
Klappt jetzt!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.11.17 18:33 
Sehr schön, gut gemacht! :zustimm:

Dann kümmern wir uns jetzt darum, dass nicht irgendwas, sondern das Gewünschte in die Listbox eingetragen wird. Erstmal der Spielername:
ausblenden Delphi-Quelltext
1:
ListBox1.Items.Add(Format('%.04d %s', [Random(1000), EditX.Text]));					

Ich habe die neuen Text-Teile markiert. Was passiert: mit dem %s sagen wir der Format()-Funktion, dass noch ein String ausgegeben werden soll (nach der Zahl). Den String müssen wir dann noch im konstanten Parameter-Array ergänzen. Das "X" musst du natürlich noch auf dein Projekt anpassen. :idea:

Die Format()-Funktion ist also sowas wie eine Text-Schablone, in die man nachträglich noch was einfügen kann. :think:

Testen und Rückmelden. :zustimm:

_________________
There are 10 types of people - those who understand binary and those who don´t.
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 18:35 
Alles klar, ich versuche es so
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 18:42 
Durch was muss ich die Random(1000) bei mir ersetzen? Ein Edit2.Text wird wohl nicht funktionieren
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.11.17 18:44 
Kein Thema, mach so, wie du möchtest, ist dein Projekt, du entscheidest, was du erklären möchtest. ;)

Oh, jetzt hast du es schon geändert. :?

Also, welche Version soll es sein (spielt letztlich keine Rolle)?

//Edit: du brauchst in dem Fall noch ein IntToStr() StrToInt() drum rum.

_________________
There are 10 types of people - those who understand binary and those who don´t.


Zuletzt bearbeitet von Narses am Mi 29.11.17 18:53, insgesamt 1-mal bearbeitet
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 18:46 
die Version nicht von dir ist für mich verständlicher/nachvollziehbarer
Funktioniert das mit dem string hier auch?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.11.17 18:49 
Also dann, Rolle rückwärts. ;)

Dann kannst du auch gleich diese Zeile an die passende Stelle im Programm verschieben, wo der neue Highscore erfasst werden soll.

Den Button und den Handler brauchen wir noch, kannste drin lassen.

_________________
There are 10 types of people - those who understand binary and those who don´t.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.11.17 18:51 
user profile iconLena00 hat folgendes geschrieben Zum zitierten Posting springen:
Funktioniert das mit dem string hier auch?
Du meinst den Spielernamen? Ne, das geht anders, einfach mit einem Plus dranhängen. Probier mal einfach selbst. Sonst sag Bescheid. ;)

_________________
There are 10 types of people - those who understand binary and those who don´t.
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 18:59 
Super hat funktioniert!! 8)
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 19:01 
Endspurt: Jetzt müssen die Zahlen noch von Hoch nach Tief geordnet werden
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.11.17 19:02 
Jup. ;) Vorher noch die Begrenzung der Anzahl oder weglassen?

_________________
There are 10 types of people - those who understand binary and those who don´t.
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 19:05 
Würde ich mittlerweile weglassen :)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.11.17 19:12 
Dann also Endspurt: wie kriegt man die Liste umgedreht... 8) Da gibt es mehrere Versionen, manche davon "eleganter" als Andere, ich schlage mal diese vor. Ist sicher nicht die beste Variante, weil die Datenhaltung in der GUI generell keine gute Idee ist, aber ich rate mal: das ist dir grade ziemlich egal, oder? :lol:

Wir werden jetzt einfach noch eine Listbox auf das Formular legen (erstmal einfach daneben), in der wir die Einträge aus der sortierten Liste umgekehrt für die Anzeige auf dem Bildschirm einfügen. Diese Listbox darf dann natürlich nicht automatisch sortieren! Die "originale" (erste) Listbox blenden wir dann einfach später aus (.Visible auf FALSE setzen, dann sieht man die nicht mehr, fertig).

In den Button-Handler kommt erstmal einfach nur rein:
ausblenden Delphi-Quelltext
1:
ListBox2.Clear;					

Vor dem Ausgeben der Liste in der neuen Listbox muss natürlich der alte Inhalt raus.

Sag bescheid, wenn du das soweit hast.

_________________
There are 10 types of people - those who understand binary and those who don´t.
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 19:24 
Bin soweit
Und jetzt muss in die neue Liste die alte andersrum ausgegeben werden
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.11.17 19:30 
Konzept: Wir werden jetzt einfach alle Einträge aus der ersten Listbox immer wieder vorne (an der ersten Position) in der zweiten Listbox einfügen. Dabei dreht sich die Reihenfolge der Elemente automatisch um. Was brauchen wir dafür?
  • Wir bauchen die Anzahl der Elemente in der ersten Listbox: Listbox1.Count
  • Wir brauchen eine for-Schleife, die über alle Elemente der ersten Listbox läuft.
  • Wir brauchen einen Befehl, der ein Element an einer bestimmten Position einer Listbox einfügt (und nicht einfach immer ans Ende stellt): Listbox2.Items.Insert(<position>, <element>)
  • Wir brauchen Zugriff auf ein Element einer Listbox: Listbox1.Items.Strings[<position>]
Damit solltest du alle "Bausteine" für die aktuelle Aufgabe beisammen haben. Was in spitzen Klammern oben angegeben ist, muss natürlich passend ersetzt werden.

Probier mal, dann sehen wir weiter. :zustimm:

_________________
There are 10 types of people - those who understand binary and those who don´t.
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 19:38 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm2.Button12Click(Sender: TObject);
begin
ListBox1.Items.Add(Copy('0000'+Edit2.Text, length(Edit2.Text)+14)+' ' + Edit3.Text);
//Zahl, die ja als Zeichenkette vorliegt, werden vorn vier nullen hinzugefügt,
//kopieren der letzten vier stellen der neuen Zeichenkette in die ListBox
Listbox1.Count
for ----
Listbox2.Items.Insert(<position>, <element>)
ListBox2.Clear;
Listbox1.Items.Strings[<position>]


Bei dem was in die Klammer muss, welcher Ausdruck,[/quote] und wie die for-Schleife aussehen muss bin ich echt überfragt... :(
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.11.17 19:46 
Zunächstmal hast du noch die Zeile im Button-Handler drin, die einen neuen Highscore einträgt. Die sollte eigentlich bereits an die "richtige" Stelle in deinem Programm verschoben sein, nämlich da hin, wo das Spiel beendet wird. Der Button-Handler ist ja nur ein Test. :idea:

Allerdings könnte es sein, dass dein Spiel etwas aufwändiger ist und es deshalb unpraktisch zum testen, immer wieder eine Runde zu spielen, nur um einen Highscore-Test zu machen... :P Ist OK, in dem Fall brauchst du aber noch einen weiteren Test-Button, in dem wir dann jetzt die Übertragung von der ersten in die zweite Listbox programmieren.

Ansonsten ist dein "Code-Vorschlag" recht wenig... sagen wir mal "strukturiert". :? Sagtest du nicht, du hast bereits die for-Schleife im Unterricht gehabt? :gruebel:

_________________
There are 10 types of people - those who understand binary and those who don´t.