Thema: Delphi Variable als Zeiger?

Einzelnen Beitrag anzeigen

Dezipaitor

Registriert seit: 14. Apr 2003
Ort: Stuttgart
1.701 Beiträge
 
Delphi 7 Professional
 
#4

Re: Variable als Zeiger?

  Alt 22. Sep 2007, 13:18
Das Problem steckt sieht doch so vereinfacht aus:
Delphi-Quellcode:
var obj1, obj2 : TAuto;
begin
  obj1 := TAuto.Create;
  obj2 := obj1; //obj2 = obj1 - obj1 und obj2 zeigen auf dasselbe Auto im Speicher
  //sind jedoch zwei verschiedene variablen, eben nur mit demselben Inhalt

  obj1.Fahre; //ok
  obj2.Fahre; //ok

  obj1.Free;
  obj1 := nil;

  if Assigned(obj1) then //False
    obj1.Fahre;
  if Assigned(obj2) then //true
    obj2.Fahre; //AV
end;
Christian
Windows, Tokens, Access Control List, Dateisicherheit, Desktop, Vista Elevation?
Goto: JEDI API LIB & Windows Security Code Library (JWSCL)
  Mit Zitat antworten Zitat