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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With