Autor Beitrag
swbo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mo 03.07.06 21:05 
Hallo,

ich möchte gerne eine ListBox mit den Werten von 1 bis 59 mit einer for Schleife füllen. Dabei entspricht ja der erste Index vom Listenfeld dem Index 0. Somit wird dann bei der Programmausführung in der ListBox nach dem Wert 59 eine weitere unschöne Leerzeile angefügt. Wie kann ich diese umgehen? Vielen Dank!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button2Click(Sender: TObject);
var i: integer;
begin
  with listbox1 do
  begin
    clear;
    for i:=1 to 59 do
    begin
      ItemIndex := 1;
      Items.add(IntToStr(i));
    end;
  end;
end;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Moderiert von user profile iconGausi: Topic aus Sonstiges (Delphi) verschoben am Di 04.07.2006 um 12:16
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 03.07.06 21:13 
:roll: Ich habe den Code übernommen und bei mir ist keine weitere Leerzeile. :roll:
Warum setzt du ItemIndex immer wieder auf 1 zurück und nicht auf 0 und warum in der Schleife und nicht danach?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
swbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mo 03.07.06 21:26 
Vielen Dank!

Nun ich habe den Code wie folgt geändert. Leider habe ich noch immer am Ende der 59 in der ListBox beim scrollen eine Leerzeile. Vielleicht ist diese auch normal?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button2Click(Sender: TObject);
var i: integer;
begin
  with listbox1 do
  begin
    clear;
    for i:=1 to 59 do
      Items.add(IntToStr(i));
    ItemIndex := 0;
  end;
end;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
swbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mo 03.07.06 21:28 
Wie kann ich eigentlich die von mir ausgewählte Zahl in eine Variable zurück geben lassen?
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 03.07.06 21:47 
Meinst du, du hast nach der 59 einen weiteren Eintrag, der aus einem Leerstring besteht? Falls ja, dann poste mal den ganzen Code.

<Wie kann ich eigentlich die von mir ausgewählte Zahl in eine Variable zurück geben lassen?>
variablenname:=strtoint(listbox1.items[listbox1.itemindex]);

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
swbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mo 03.07.06 22:38 
Eigentlich ist das der ganze Code. Da gab ja noch die Möglichkeit mit ListBox1.Items.Count -1 zu arbeiten. Aber da habe ich wohl etwas falsch gemacht, hat nicht geklappt, oder ich sehe bei den Beispielen nicht durch.
swbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mo 03.07.06 22:40 
Ja, genau diesen Leerstring meine ich ... :)
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 03.07.06 22:42 
:roll: Ich übernehm den Code mit Copy & Paste und es ist kein leerer Eintrag am Ende :roll: Lad mal dein Projekt hoch (Archiv mit allen Dateien)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 04.07.06 17:10 
Lade dein Projekt bitte hier hoch. ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
swbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Di 04.07.06 19:27 
Ich habe Dir den Code als private Nachricht geschickt.
ByteKiller
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 32

Win Vista, XP Pro SP2
Delphi 7 (Delphi 2005)
BeitragVerfasst: Di 04.07.06 21:51 
Hi,
ich hab das selber ma probiert und da is keine Leerzeile!
Folgender Quelltext meinerseits:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
begin
  for i:= 1 to 59 do
    Listbox1.Items.add(inttostr(i));
end;


Mfg ByteKiller