constructor TAutoClean.Create(AObj: TObject); begin FObj := AObj; end;
destructor TAutoClean.Destroy; begin FreeAndNil(FObj); inherited; end;
А теперь будем использовать его вместо объекта: procedure TForm1.Button1Click(Sender: TObject); var a: IAutoClean; //must declare as local variable, so when this procedure finished, it's out of scope o: TOpenDialog; //any component begin o := TOpenDialog.Create(self); a := TAutoClean.Create(o); if o.Execute then ShowMessage(o.FileName); end; Взято с Delphi Knowledge Base http://www.baltsoft.com/