Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/ActiveX    [ Add a report in this area ]  
Report #:  100820   Status: Closed
Delphi XE2: Dynamic binding Ole-Excel crashes in DispatchInvoke
Project:  Delphi Build #:  16.0.4316.44803
Version:    16.2 Submitted By:   Tom Mueller
Report Type:  Basic functionality failure Date Reported:  11/7/2011 7:32:10 AM
Severity:    Critical / Show Stopper Last Updated: 8/17/2012 7:41:46 PM
Platform:    All versions Internal Tracking #:   288672
Resolution: Fixed (Resolution Comments) Resolved in Build: : Update 3
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 2
Description
Dynamic Ole-binding causes type mismatch error due to wrong parameter order in DispatchInvoke.
Steps to Reproduce:
Make a dynamic Excel-Ole binding and call an excel-method with more than one parameter:

----
oExcelObj:= CreateOleObject('Excel.Application');
oExcelObj.Visible:= True;
oExcelObj.WorkBooks.Add;
oExcelObj.ActiveSheet.Cells.Find(What:= 'Test', LookAt:= $00000001);
---

See also the attached test project.
Workarounds
none
Attachment
XE2_Ole_DispatchInvoke.zip
Comments

Tom Mueller at 11/7/2011 7:46:27 AM -
See also the detailed description of the error in the attached XE2_Ole_DispatchInvoke_20111107.pdf

Guenther Schoch at 11/7/2011 11:06:53 PM -
Tested the suggestion provided by Jean-Marie Babet  

--- System.Win.ComObj.pas (revision 44871)
+++ System.Win.ComObj.pas (working copy)
@@ -1820,7 +1820,10 @@
   Src := Names;
   for I := 0 to NameCount-1 do
   begin
-    WideNames[I] := UTF8ToWideString(Src);
+    if I = 0 then
+      WideNames[I] := UTF8ToWideString(Src)
+    else
+      WideNames[NameCount-I] := UTF8ToWideString(Src);
     Inc(Src, StrLen(Src)+1);
   end;
   Temp := Dispatch.GetIDsOfNames(GUID_NULL, WideNames, NameCount,



and it works!

regards

Günther (gs-soft)

For Now at 12/8/2011 11:53:48 AM -
Same problem on Late binding to Word with XE2 (no problem up to XE, runs with Word 2003, 2007, 2010 on Vista and Win7 32bit). Jean-Marie's Workaround provided by Günther also works fine.

Sample code:

implementation

{$R *.dfm}

uses
  ActiveX, comobj;

procedure TForm1.Button1Click(Sender: TObject);
const
  wdGoToBookmark = $FFFFFFFF;
  wdLine = $00000005;
  wdFormatHTML = $00000008;
  wdUnderlineSingle = $00000001;
  wdDoNotSaveChanges = $00000000;
var
  lWordApp: Variant;
  lStr: String;
begin
  try
    lWordApp := CreateOleObject('Word.Application');
    lWordApp.Visible:= true;

    // doesn't work with XE2: type conflict
    lWordApp.Documents.Add(Template:= 'myTemplate.dot', NewTemplate:= False);
    // this works
    // lWordApp.Documents.Add(Template:= 'myTemplate.dot');

    lWordApp.ActiveDocument.AttachedTemplate.Saved := True;

    // doesn't work with XE2: wrong parameter
    lWordApp.Selection.GoTo(What:= wdGoToBookmark, Name:= 'Text');
    // this works
    // lWordApp.Selection.GoTo(Name:= 'Text');

    lWordApp.Selection.Font.Size := 14;
    lWordApp.Selection.Font.Bold := True;
    lWordApp.Selection.Font.Italic := True;
    lWordApp.Selection.Font.Underline := wdUnderlineSingle;
    lWordApp.Selection.TypeText(Text:= 'Late binding OLE Automation');
    lWordApp.Selection.MoveLeft( Count:= 2);

    // doesn't work with XE2: wrong parameter
    lWordApp.Selection.MoveDown(Unit:=wdLine, Count:= 1);
    // this works
    // lWordApp.Selection.MoveDown(Unit:=wdLine);
    // and this works
    // lWordApp.Selection.MoveDown(Count:= 1);

    lWordApp.Selection.ParagraphFormat.KeepWithNext:= True;

    // doesn't work with XE2: type conflict
    lWordApp.ActiveDocument.SaveAs(FileName:= 'myDocument.html', FileFormat:= wdFormatHtml);
    // this works
    // lWordApp.ActiveDocument.SaveAs(FileName:= 'myDocument.doc');

    lStr:= lWordApp.ActivePrinter;
    lWordApp.ActiveDocument.Close(wdDoNotSaveChanges);
  finally
    lWordApp := Unassigned;
  end;
end;

end.

Kind regards
Kurt

Tomohiro Takahashi at 12/8/2011 7:02:02 PM -
This issue will be fixed in upcoming next update release.
So, if possible, please retest your issue with it in the near future.

Ronald Hoek at 4/25/2012 2:00:19 AM -
Is this fix a common fix for 'Type mismatch' exceptions, when dealing with ActiveX?

I'm using a ActiveX control (Farpoint Spread 8) and when I use late binding with the function

function GetCustomFunction(const FuncName: WideString; var MinArgs: Smallint; var MaxArgs: Smallint; var Flags: CustomFunctionFlagsConstants): WordBool;

I also get an 'Type mismatch' exception.
None of the parameters are optional.

(CustomFunctionFlagsConstants = TOleEnum)

Ronald Hoek at 4/25/2012 2:46:04 AM -
NOTE: I've XE2 update 4 installed!

Tomohiro Takahashi at 4/25/2012 3:49:18 AM -
Could you please put new QC report about your issue?

Server Response from: ETNACODE01