Autor Beitrag
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 16:48 
Du meintest ja sie werden als "Zeichenkette" gelesen, vielleicht gibt es ja eine andere Möglichkeit
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 16:51 
Zeichenkette statt Zahl ist schon das, was wir wollen. Zum einen kann die Listbox gar nix anderes (:lol:, naja, das mit den TObjects geht schon noch, aber das hattest du ja schon, ist erstmal zu schwer), zum anderen wollen wir später ja auch noch die Spielernamen mit dazu tun. :idea:

OK, kleiner Schubs: wie ist das denn so mit rechts- und linksbündig, hilft das vielleicht was? :zwinker:

_________________
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 17:05 
Das wirft ejtzt noch eher ein Fragezeichen auf... aber theoretisch müssten die Zahlen ja schon "linksbündig" sein, weil man sie ja "von links liest", heißt, die Anzahl der Stellen der Zahl und das "von links geordnet" gibt die Reihenfolge an
Hoffentlich etwas verständlich was ich mein
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 17:08 
Ich versteh dich schon, sonst frag ich einfach. ;) Und das tue ich auch gleich: sicher, dass du nicht zufällig Links und Rechts im Kopf "vertauscht" hast beim Schreiben? :zwinker:

_________________
There are 10 types of people - those who understand binary and those who don´t.
Symbroson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 382
Erhaltene Danke: 67

Raspbian, Ubuntu, Win10
C, C++, Python, JavaScript, Lazarus, Delphi7, Casio Basic
BeitragVerfasst: Mi 29.11.17 17:15 
Hast du schonmal schriftlich Zahlen addiert? Das hilft vielleicht

_________________
most good programmers do programming not because they expect to get paid or get adulation by the public, but because it's fun to program. (Linus Torvalds)
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 17:18 
Ja klar! :D
okay, mein Denkfehler
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 17:19 
Aber kein Plan wie das bei Delphi umgesetzt wird
Symbroson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 382
Erhaltene Danke: 67

Raspbian, Ubuntu, Win10
C, C++, Python, JavaScript, Lazarus, Delphi7, Casio Basic
BeitragVerfasst: Mi 29.11.17 17:21 
welchen Wert hat denn die Hunderterstelle von 64?

_________________
most good programmers do programming not because they expect to get paid or get adulation by the public, but because it's fun to program. (Linus Torvalds)
Lena00 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65
Erhaltene Danke: 4



BeitragVerfasst: Mi 29.11.17 17:33 
Die existiert nicht
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 17:35 
Und welcher Ziffer entspricht "nix"? :zwinker:

_________________
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 17:36 
einer 0
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 17:40 
Na, war doch gar nicht so schwer. :zustimm: Wenn man also die Text-Zahlen "vorne" mit Nullen "auffüllt", dann werden die bei einem Textvergleich trotzdem korrekt sortiert. :idea:

Aber wie macht man das? Kein Rätselraten, das geht so: :les:
ausblenden Delphi-Quelltext
1:
ListBox1.Items.Add(Format('%.04d', [Random(1000)]));					

Was passiert da? :lupe: Das schreibe ich dir in den nächsten Beitrag, inzwischen probiert du das einfach mal aus. ;)

_________________
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 17:46 
Zerlegen wir mal die Zeile:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
ListBox1.Items.Add(Format('%.04d', [Random(1000)]));
// -->
Random(1000// Zufallszahl zwischen 0..999 auswürfeln
[Random(1000)] // die Klammern machen aus der Zufallszahl ein konstantes Array mit einem Wert (ist nicht weiter wichtig jetzt, aber die Format()-Funktion will das so haben, kannst ja mal in der Online-Hilfe nachlesen
Format('%.04d', [Random(1000)]) // die Format()-Funktion gibt (hier: eine Zahl; allgemein: die Parameter in den eckigen Klammern) im gewünschten "Format" (hier: .04d) aus
// das %-Zeichen leitet eine Variable ein
// der Punkt steht für die Stellenanzahl
// die 0 für "mit führenden Nullen" ausgeben
// die 4 für die Anzahl der Stellen, eben 4
// das d für eine Dezimalzahl (Integer)

// den Rest kennst du schon, der fügt eine Zeile in die Listbox ein


Ausprobiert? Klappt? ;)

_________________
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 17:53 
Ausprobiert und ja es funktioniert, jetzt müssen sie noch sortiert werden und meine Zahlen müsssen aus einem Edit-Feld entnommen 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 17:55 
Ähm, sortiert sollten sie doch schon sein, oder hast du die Eigenschaft .Sorted der Listbox wieder auf FALSE gestellt? :gruebel:

_________________
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:00 
Im Objektinspektor ist sorted auf true gestellt
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:03 
Du bist etwas spärlich mit den Rückmeldungen, ich kann deinen Bildschirm ja nicht sehen... :lupe: :les: ;)

Werden die Zufallszahlen jetzt korrekt sortiert in der Listbox angezeigt, wenn du den Button ein paar mal angeklickt hast (klar, "falsch" rum, du willst ja absteigend haben, kommt noch)?

_________________
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:08 
Nein sie werden nicht geordnet angezeigt
Bild der Box im Anhang
Einloggen, um Attachments anzusehen!
Symbroson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 382
Erhaltene Danke: 67

Raspbian, Ubuntu, Win10
C, C++, Python, JavaScript, Lazarus, Delphi7, Casio Basic
BeitragVerfasst: Mi 29.11.17 18:11 
darf ich nochmal dazwischengrätschen ;)
Zitat:
Zahlen müsssen aus einem Edit-Feld entnommen werden

Die Zahlen aus dem Edit-Feld zu holen sollte kein Problem sein. Du musst nur anstatt den Zufallszahlen die Zahlen aus den TextEdits in die ListBox hinzufügen.
Die zu Formatieren geht umständlich nach der eben von Narses beschriebenen Methode:
ausblenden Delphi-Quelltext
1:
ListBox.Items.Add(Format('%.04d', [strtoint(Edit.Text)]);					

oder effizient:
ausblenden Delphi-Quelltext
1:
ListBox.Items.Add(Copy('0000'+Edit.Text, length(Edit.Text)+14));					

Dabei fügen wir einfach unserer Zahl, die ja schon als Zeichenkette vorliegt, vorne vier nullen hinzu, und kopieren dann sozusagen die letzten vier stellen der neuen Zeichenkette in die ListBox.
Wir umgehen somit die Umwandlung einer Zeichenkette in einen Integerwert und die Formatierung

_________________
most good programmers do programming not because they expect to get paid or get adulation by the public, but because it's fun to program. (Linus Torvalds)


Zuletzt bearbeitet von Symbroson am Mi 29.11.17 18:17, insgesamt 4-mal bearbeitet
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:13 
OK, kann es sein, dass du noch Code(-Reste) von dem vorigen Versuch drin hast (mit den TObjects), so dass die Listbox nicht wie erwartet funktioniert? :lupe:

Mach mal folgendes: lösche die Listbox wieder aus dem Formular, dann kommentierst du die Zeile mit dem Zahl-Einfügen in der Button-Methode aus (einfach zwei Schrägstriche an den Anfang der Zeile machen). Jetzt versuchen zu compilieren: falls es noch Rest vom ersten Versuch gibt, sollten die jetzt als Fehler aufploppen: rauslöschen, bis sich das Programm wieder kompilieren lässt. :idea:

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