What is the correct way to work with LateBinding in Delphi?

I actually use late binding in delphi, and I need to know that this is the right way to work with it.

My main problem is how do I handle the memory used by these objects, should I free the memory?

check this code example

var
  chEaten: Integer;
  BindCtx: IBindCtx;
  Moniker: IMoniker;
 MyObject:: IDispatch;
begin
try  
  OleCheck(CreateBindCtx(0, bindCtx));
  OleCheck(MkParseDisplayName(BindCtx, StringToOleStr('oleobject.class'), chEaten, Moniker));
  OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, MyObject));

  MyObject.Metod1();
  MyObject.Metod2();
 finally
 MyObject:=nil,// is  this necesary?
 end;

end;

it would be helpful if someone briefly explained how memory is processed in this type of object.

early.

+3
source share
2 answers

COM- Delphi . AddRef Release , Release, . , , nil .

+3

, . StringToOleStr() BSTR, SysFreeString(). WideString, , :

OleCheck(MkParseDisplayName(BindCtx, PWideChar(WideString('oleobject.class')), chEaten, Moniker)); 

:

var
  w: WideString;

w := 'oleobject.class';
OleCheck(MkParseDisplayName(BindCtx, PWideChar(w), chEaten, Moniker)); 
0

Source: https://habr.com/ru/post/1770642/


All Articles