Autor Beitrag
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 06.02.03 15:24 
ich habe eine TListbox, in der ich nicht nur strings stehen habe, sondern dahinter steht auch jeweils ein Objekt.

Einfügen geht mit
ausblenden Quelltext
1:
meineliste.AddItem(anzeigestring, Objekt)					

Das scheint so weit zu klappen.
Problem ist: Wie komme ich an das entsprechende Objekt wieder dran, wenn ich einen speziellen Eintrag markiere? D.h. ich will über die Liste wieder das Objekt dahinter erhalten.
Ich nehme an, das das ganz einfach ist, und ich nur wieder mal n Brett vorm Kopf habe. Oder geh ich die Sache ganz falsch an?
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 06.02.03 15:29 
Hallo
Onlinehilfe hat folgendes geschrieben:

Items.Objects[ItemIndex]


Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Gausi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 06.02.03 17:59 
danke, das klappt, aber jetzt stehe ich vor einem neuen Problem:
der rückgabewert von ".items.objects[i];" ist vom Typ "Tobject".
Wenn ich also
ausblenden Quelltext
1:
 tmp:=meineliste.items.objects[i];					

schreibe, dann muss tmp als TObject deklariert werden.

Das Objekt, das bei mir hinter dem Listeneintrag steckt, ist aber ein Record (eine von TObject abgeleitete Klasse). Wie kann ich dann auf die verschiedenen Daten in dem Record zugreifen?
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 06.02.03 19:07 
ausblenden Quelltext
1:
2:
3:
tmp:=TMyobjekt(meineliste.items.objects[i])
oder 
tmp:=meineliste.items.objects[i] as Tmyobjekt

solltest aber vorher mit is prüfen, ob das Objekt wirklich dem Typ entspricht, denn du willst.
ausblenden Quelltext
1:
if meineliste.items.objects[i] is TmyObjekt then   ....					


edit: uups, das gilt für Objekte, ob das mit records klappt, weiß ich nicht,
ansonsten versteh ich bei
Zitat:

Record (eine von TObject abgeleitete Klasse).
erstmal Bahnhof .

Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Gausi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 06.02.03 19:16 
Danke, Danke, Danke, endlich klappt es :D