Freeing OleVariant after using CreateOleObject

Here is a simple code:

procedure Test;
var
  V: OleVariant;
begin
  V := CreateOleObject('ADOX.Catalog');
  try
    // do something with V...
  finally
    V := Unassigned; // do we need this?
  end;
end;

Do we need to use the V := Unassigned code at the end, or will V is free when it exists the scope of Test procedure? in VB you set the variable to Nothing. do we need to do the same here? ie:

function VarNothing: IDispatch;
// emulate VB function SET VarX = Nothing
var
  Retvar: IDispatch;
begin
  Retvar := nil;
  Result := Retvar;
end;

// do something with V and finally:
V := VarNothing;

Answers


OleVariant will release the interface automatically when it goes out of scope. You can assign a new value to the OleVariant if you need it to be released sooner.


Need Your Help

media queries and to adapt the ready made site

javascript html css

I am now having to adjust my current site to fit it into a smaller desktop screen size. It is viewable on all screens, only with smaller ones like 14", it creates a scrollbar on the left and is not

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.