Autor Beitrag
Zombimode
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Win 98, Win XP

BeitragVerfasst: So 01.05.05 13:46 
Moin

Ich brauch den String aus dem gerade ausgwählten item einer Listbox.
Ich hab in der Delphihilfe gelesen, dort zwar eine ganze menge interessanter Dinge gefunden, aber nicht die Methode, nach der ich suche.

Weiß jemand, wie man das anstellen kann?
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: So 01.05.05 14:02 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.ListBox1Click(Sender: TObject);
var
 i: integer;
begin
  i:= ListBox1.ItemIndex;
  Memo1.Lines.Add(ListBox1.Items.Strings[i]);
end;
Muetze1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 346



BeitragVerfasst: So 01.05.05 14:20 
Moin!

Blackheart's Code hat einen Fehler, wenn kein Item ausgewählt ist, dann bekommt er einen Zugriffsfehler, oder wenn man ordentlich die Bereichsprüfung nutzt eine ERangeCheck Exception.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.ListBox1Click(Sender: TObject);
var
 i: integer;
begin
  i := ListBox1.ItemIndex;
  If ( i > -1 ) Then
    Memo1.Lines.Add( ListBox1.Items.Strings[i] );
end;


MfG
Muetze1
Zombimode Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Win 98, Win XP

BeitragVerfasst: So 01.05.05 14:32 
Wie einfach doch die Lösungen für manche Probleme der Welt sind ;)
Dank' euch beiden :)
Zombimode Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Win 98, Win XP

BeitragVerfasst: So 01.05.05 17:24 
leider gibts doch noch probleme

folgender Quelltext
ausblenden Delphi-Quelltext
1:
2:
for i := 0 to listbox1.Count do
   if listbox1.Selected[i] = true then k := i;

spukt zur laufzeit, wenn die schleife eigentlich abgelaufen sein sollte, diese fehlermeldung aus: "...list index out of bounds(zahl der items der liste)"

wieso das?
und was kann man dagegen tun?
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 01.05.05 17:26 
user profile iconZombimode hat folgendes geschrieben:
leider gibts doch noch probleme

folgender Quelltext
ausblenden Delphi-Quelltext
1:
2:
for i := 0 to listbox1.Count do
   if listbox1.Selected[i] = true then k := i;

spukt zur laufzeit, wenn die schleife eigentlich abgelaufen sein sollte, diese fehlermeldung aus: "...list index out of bounds(zahl der items der liste)"

wieso das?
und was kann man dagegen tun?


Weil du auf ein String zu greifen willst den es gar nicht existiert. Der Quelltext müsste so heißen:

ausblenden Delphi-Quelltext
1:
2:
for i := 0 to listbox1.Count-1 do
   if listbox1.Selected[i] = true then k := i;
Zombimode Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Win 98, Win XP

BeitragVerfasst: So 01.05.05 17:30 
heut ist nicht mein tag :roll:
das ist mir eben auch grad eingefallen

egal, danke trotzdem