Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi for schleife will nicht (https://www.delphipraxis.net/40479-schleife-will-nicht.html)

herrentor 16. Feb 2005 12:45


for schleife will nicht
 
ich hab ein problem mit einer for schleife. hab schon alles versucht. mein ziel: für alle items in der combobox soll eine zeile geschrieben werden.

Delphi-Quellcode:

for i:=0 to combobox.ControlCount do

    Ini.WriteString('Menüs','Menü 1',combobox.items[i]);
warum läuft die schleife nicht bis zum letzten item, sondern schreib nur itemindex 0 hin.

toms 16. Feb 2005 12:47

Re: for schleife will nicht
 
Zitat:

for i:=0 to combobox.ControlCount do
Durchläuft nicht die Items der ComBobox.
Siehe OLH: ControlCount

Richtig:
Delphi-Quellcode:
for i:=0 to ComboBox.Items.Count -1 do
begin
 ...
end;

alcaeus 16. Feb 2005 12:48

Re: for schleife will nicht
 
Deshalb:
Delphi-Quellcode:
for i:=0 to combobox.ControlCount do
Schreib mal
Delphi-Quellcode:
for i:=0 to combobox.Items.Count-1 do
Greetz
alcaeus

[edit]Das war 100%ig gleichzeitig[/edit]

toms 16. Feb 2005 12:49

Re: for schleife will nicht
 
Zitat:

Zitat von alcaeus
Deshalb:
Delphi-Quellcode:
for i:=0 to combobox.ControlCount do
Schreib mal
Delphi-Quellcode:
for i:=0 to combobox.Items.Count do
Greetz
alcaeus


Delphi-Quellcode:
combobox.Items.Count -1
:wink:

Ultimator 16. Feb 2005 12:50

Re: for schleife will nicht
 
In der Schleife lässt du ja auch für jedes Item das gleiche hinschreiben, nämlich unter der Sektion "Menü" in den Eintrag "Menü1".
Außerdem musst du Combobox.Items.Count nehmen ;-)
Probiers mal so:
Delphi-Quellcode:
for i:=0 to combobox.Items.Count do

    Ini.WriteString('Menüs','Menü '+inttostr(i),combobox.items[i]);

herrentor 16. Feb 2005 12:53

Re: for schleife will nicht
 
ja stimmt, aber jetzt schreib er nur die ersten beiden.

ist schon gut, weiß woran es liegt. danke


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:10 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz