System.TObject.DisposeOf

De RAD Studio API Documentation
Aller à : navigation, rechercher

Delphi

procedure DisposeOf; {$IFNDEF AUTOREFCOUNT} inline; {$ENDIF}

C++

void __fastcall DisposeOf();

Propriétés

Type Visibilité  Source Unité  Parent
procedure
function
public
System.pas
systobj.h
System TObject


Description

DisposeOf force l'exécution du code de destruction dans un objet.

C'est un artefact de versions antérieures dans lesquelles les compilateurs de Delphi supportaient le comptage des références automatiques. Dans les versions actuelles de Delphi, DisposeOf est utilisé comme un wrapper qui invoque TObject.Free.

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.

Voir aussi