Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which one is better in terms of performance, the early binding or late binding in Delphi COM objects

Tags:

com

delphi

In delphi, if you want to create COM object, you can do it in two ways,

the first one is early binding, for example,

uses
  MSScriptControl_TLB; // MS Script Control

var
  obj: IScriptControl;
begin
  obj := CreateOleObject('ScriptControl') as IScriptControl;
  .. 
  ..
  obj.ExecuteStatement('Msgbox 1') 
end;

Or, you can do it as following (late binding)

var
  obj: OleVariant;

begin
  obj := CreateOleObject('ScriptControl') ;
  obj.ExecuteStatement('Msgbox 1');
end;

which one is better in terms of performance?

like image 824
justyy Avatar asked Jun 29 '13 18:06

justyy


1 Answers

Which one is better in terms of performance?

Early bound is quicker than late bound. Late bound method dispatch involves the following:

  1. Looking up the entry point from the name.
  2. Assembling the parameters to be passed to the method, and performing any necessary type conversions.
  3. Calling the function.
  4. Unmarshalling any out parameters and the return value.

Many of these steps are not present at all for early bound dispatch.

Of course, if the function does anything significant at all, the performance different during method dispatch may well not be detectable.

like image 76
David Heffernan Avatar answered Nov 10 '22 09:11

David Heffernan