Autor Beitrag
Christian V.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Sa 05.04.08 13:18 
Ich will mit meinem Objekt auf ein Icon zugreifen können. Dafür setze ich durch eine Methode den Pointer.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
type
  PIcon = ^TIcon;
//FIcon ist ein Feld vom Typ PIcon
...
procedure TKlasse.SetIcon(Icon: TIcon);
begin
  FIcon := @Icon;
end;


//auf der Form die das Objekt instanziert:
...
Klasse.SetIcon(Application.Icon);
...


Wenn ich nun später auf das Handle in der Klase zugreifen will, wollte ich das so machen:
ausblenden Delphi-Quelltext
1:
Handle := FIcon^.Handle;					


Der Compiler gibt keine Warnungen oder Fehler aus, zur Laufzeit bekomme ich eine Zugriffsverletzung wenn ich FIcon dereferenziere.

//edit:

ok, habe gerade gemerkt dass Application.Icon ja ein Property, hängt das damit zusammen? Man kann doch nur auf ein Property kein Pointer machen, aber das Property gibt mir ja die Referenz auf ein TIcon.

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Sa 05.04.08 13:36 
Für Klassen-Variablen brauchst du keine Pointer. Die Variablen sind selber Pointer - du greifst immer auf das Objekt zu. Beim Zuweisen wird nur die Adresse kopiert, nicht das Objekt selber. Du kannst immer noch auf das Ausgangsobjekt zugreifen.
Christian V. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Sa 05.04.08 13:42 
Stimmt, du hast recht. Ich habe es jetzt so abgeändert und es funktioniert jetzt. Danke!

Ich würde aber trotzdem noch gerne Wissen, warum es vorhin nicht funktioniert hat.

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?