Autor Beitrag
SteheAufDerLeitung
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 104



BeitragVerfasst: Mo 03.09.07 11:41 
Hallo!

Ich habe eine ComboBox, gefüllt mit Objekten einer Klasse "System". Ich möchte jedes einzelne auf die Eigenschaft .ID überprüfen.

Um an das eigentliche Objekt zu gelangen mach ich folgendes:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var hSystem : System;

for hCnt := 0 to ComboBox.Items.Count-1 do begin
  hSystem := ISystem(pointer(ComboBox.Items.Objects[hCnt]));
  if hSystem.ID = ...
  end;


Doch hSystem ist immer "nil". Wieso? Greif ich falsch auf die Systeme zu??

Grüße und Dank

Sebastian
jackle32
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 183
Erhaltene Danke: 7

Win7
Delphi XE5 Starter, RAD Studio XE7 Pro
BeitragVerfasst: Mo 03.09.07 12:31 
Also ich muss sagen ich kenne den Variablentyp "System" nicht, aber warum liest du nicht gleich die ID aus?

Müsste doch genauso funktionieren wenn du machst

ausblenden Delphi-Quelltext
1:
2:
3:
for hCnt := 0 to ComboBox.Items.Count-1 do begin
  if ComboBox.Items.Objects[hCnt].ID = ... 
end;


Oder hat es irgendeinen speziellen Grund warum du erst ein Pointer auf das Object. Und was macht dann ISystem?

Gruß Jack
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Mo 03.09.07 12:38 
Der Cast auf iSystem ist schon in Ordnung, ein TObject hat nunmal keine ID. Der Cast auf Pointer ist überflüssig und möglicherweise auch die Fehlerursache.

_________________
Bravery calls my name in the sound of the wind in the night...