System.TObject.DisposeOf

Aus RAD Studio API Documentation
Wechseln zu: Navigation, Suche

Delphi

procedure DisposeOf; {$IFNDEF AUTOREFCOUNT} inline; deprecated 'Use Free instead'; {$ENDIF}

C++

void __fastcall DisposeOf();

Eigenschaften

Typ Sichtbarkeit Quelle Unit Übergeordnet
procedure
function
public
System.pas
systobj.h
System TObject


Beschreibung

DisposeOf erzwingt die Ausführung des Destruktorcodes in einem Objekt.

Diese Methode war ein Artefakt aus früheren Versionen, als die mobilen Delphi-Compiler die automatische Referenzzählung (Automatic Reference Counting, ARC) unterstützten. In aktuellen Versionen von Delphi, wird DisposeOf als Wrapper verwendet, der TObject.Free aufruft.

type
  TMySimpleClass = class
  private
    stringMember: String;
    constructor Create(const Text: String);
    destructor Destroy;
  end;

constructor TMySimpleClass.Create(const Text: String);
begin
  stringMember := Text;
end;

destructor TMySimpleClass.Destroy;
begin
  // this will be executed on calling the DisposeOf method.
end;

var
  myObject: TMySimpleClass;
begin
  myObject := TMySimpleClass.Create('This is a code snippet indicating the usage of the DisposeOf method');
  try
    // Use 'myObject' here
  finally
    myObject.DisposeOf;
  end;
end.

Siehe auch