سؤال

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;
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top