which one is better in terms of performance, the early binding or late binding in Delphi COM objects
com, delphi
Solution
Which one is better in terms of performance?
Early bound is quicker than late bound. Late bound method dispatch involves the following:
- Looking up the entry point from the name.
- Assembling the parameters to be passed to the method, and performing any necessary type conversions.
- Calling the function.
- 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.
Problem
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?