View Issue Details

IDProjectCategoryView StatusLast Update
0037355FPCCompilerpublic2020-07-31 17:56
ReporterSergey Tsukanov Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0037355: OLE automation object methods call using named parameters not work in FPC 3.2.0
Description...
w := CreateOleObject('Word.Application');
...
  w.Documents.Add(NewTemplate:=true); // this works only in FPC 3.0.4(Lazarus 2.0.8), in FPC 3.2.0 (Lazarus 2.0.10) get error "Method 'Add' is not supported by automation object"
Steps To ReproduceCreate new application in Lazarus 2.0.10 and place button in form... or use attached file

Button OnClick handler:
procedure TForm1.Button1Click(Sender: TObject);
  var w:variant;
begin
  w := CreateOleObject('Word.Application');
  w.Visible := true;
  {
  https://docs.microsoft.com/ru-ru/office/vba/api/word.documents.add
  Word.Documents.Add (Template, NewTemplate, DocumentType, Visible)
  }
  //w.Documents.Add(,true); //no errors, this works in FPC 3.0.4(Lazarus 2.0.8) and FPC 3.2.0 (Lazarus 2.0.10)
  w.Documents.Add(NewTemplate:=true); // this works only in FPC 3.0.4(Lazarus 2.0.8), in FPC 3.2.0 (Lazarus 2.0.10) get error "Method 'Add' is not supported by automation object"
  w := UnAssigned;
end;
TagsNo tags attached.
Fixed in Revision45974
FPCOldBugId
FPCTarget-
Attached Files

Activities

Sergey Tsukanov

2020-07-15 05:41

reporter  

OLE Named Param.zip (130,096 bytes)

Sven Barth

2020-07-15 15:12

manager   ~0124039

I can not reproduce with Lazarus 2.0.10 and FPC 3.2.0 on i386-win32 and x86_64-win64.

Also please provide an example that does not depend on Lazarus.

Sergey Tsukanov

2020-07-15 16:20

reporter   ~0124045

Last edited: 2020-07-15 16:40

View 2 revisions

.pas and .exe file compiled in FPC 3.2.0 attached.

compile in FPC 3.0.4 and run, no errors, MSWord started and open new template...
c:\Tmp\OLENamedParams>c:\Lazarus208\fpc\3.0.4\bin\i386-win32\fpc.exe c:\Tmp\OLENamedParams\onp_err.pas
Free Pascal Compiler version 3.0.4 [2020/04/11] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling c:\Tmp\OLENamedParams\onp_err.pas
Linking c:\Tmp\OLENamedParams\onp_err.exe
21 lines compiled, 3.2 sec, 208784 bytes code, 8756 bytes data

c:\Tmp\OLENamedParams>onp_err.exe
Press Enter to start MS Word...
no error
Press Enter to exit...


compile in FPC 3.2.0 and run, error: "Method 'Add' is not supported by automation object", MSWord is running but does not open a new template ...
c:\Tmp\OLENamedParams>C:\Lazarus2010\fpc\3.2.0\bin\i386-win32\fpc.exe c:\Tmp\OLENamedParams\onp_err.pas
Free Pascal Compiler version 3.2.0 [2020/07/07] for i386
Copyright (c) 1993-2020 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling c:\Tmp\OLENamedParams\onp_err.pas
Linking c:\Tmp\OLENamedParams\onp_err.exe
21 lines compiled, 2.6 sec, 228032 bytes code, 10228 bytes data

c:\Tmp\OLENamedParams>onp_err.exe
Press Enter to start MS Word...
EEROR:Method 'Add' is not supported by automation object
Press Enter to exit...

I tried on 2 different PCs, the result is the same. Win10 x64, MS Office 2007.
Maybe I'm doing something wrong?
onp_err.zip (122,172 bytes)

Sergey Tsukanov

2020-07-15 16:25

reporter   ~0124046

p.s.
onp_err.pas:

program onp_err;
{$MODE OBJFPC}
uses SysUtils, ComObj;
var w:variant; err:string;
begin
  write('Press Enter to start MS Word...');
  readln;
  try
  err := '';
  w := CreateOleObject('Word.Application');
  w.Visible := true;
  w.Documents.Add(NewTemplate:=true); // this works only in FPC 3.0.4(Lazarus 2.0.8), in FPC 3.2.0 (Lazarus 2.0.10) get error "Method 'Add' is not supported by automation object"
  w := UnAssigned;
  except on E:Exception do
    err := 'EEROR:' + e.Message;
  end;
  if err='' then writeln('no error') else writeln(err);
  write('Press Enter to exit...');
  readln;
end.

Sergey Tsukanov

2020-07-15 16:34

reporter   ~0124047

attached .exe compiled in fpc 3.0.4 works without errors
onp_err_fpc304_NO_ERR.zip (112,430 bytes)

Sven Barth

2020-07-15 22:28

manager   ~0124066

Ah, it's about running the code, not compiling it! Sorry I misunderstood that.

Well, then I can't help here, cause I don't have Word to test this... (unassigning myself in the hope that someone else can take it up)

Sergey Tsukanov

2020-07-16 04:18

reporter   ~0124071

Last edited: 2020-07-16 04:33

View 3 revisions

Example for Internet Explorer, the situation is the same, it works without errors when compiling in FPC 3.0.4 and get error(and URL not opened) when compiling in FPC 3.2.0
Please, test it.

onp_err.pas:
program onp_err;
 {$MODE OBJFPC}
 {$macro on}
 uses SysUtils, ComObj;
 var w:variant; err:string;
 begin
   writeln('FPC ver.: '+ IntToStr(FPC_FULLVERSION));
   write('Press Enter to start IE...');
   readln;
   try
   err := 'no error';
   w := CreateOleObject('InternetExplorer.Application');
   w.Visible := true;
   w.Navigate(url:='https://bugs.freepascal.org/view.php?id=37355');
   w := UnAssigned;
   except on E:Exception do
     err := 'ERROR: ' + e.Message;
   end;
   writeln(err);
   write('Press Enter to exit...');
   readln;
 end.

console output:
FPC ver.: 30200
Press Enter to start IE...
ERROR: Method 'Navigate' is not supported by automation object
Press Enter to exit...

FPC ver.: 30004
Press Enter to start IE...
no error
Press Enter to exit...

Sven Barth

2020-07-16 07:37

manager   ~0124072

Okay, with that test I can reproduce it. Thank you!

Sergey Tsukanov

2020-07-17 10:51

reporter   ~0124119

Parameter "Names" for procedure "SearchIDs" in module "ComObj" is set of strings separated zero symbol.
First string contains called procedure name of COM object, next strings contains procedure parameter names.
In FPC 3.0.4 after first string one zero symbol. In FPC 3.2.0 - two zero symbols - this leads to incorrect operation, and an error when calling DispatchInterface.GetIDsOfNames.(parameter "NamesArray" is incorrect)

One of the possible solutions:
In the file "fpc \ 3.2.0 \ source \ packages \ winunits-base \ src \ comobj.pp" replace the string 1430:
 
inc(Names,NameLen+1);

to string

inc(Names,NameLen+1); if Names^=#0 then inc(Names);

Sven Barth

2020-07-31 17:56

manager   ~0124437

Please test and close if okay.

Issue History

Date Modified Username Field Change
2020-07-15 05:41 Sergey Tsukanov New Issue
2020-07-15 05:41 Sergey Tsukanov File Added: OLE Named Param.zip
2020-07-15 15:12 Sven Barth Assigned To => Sven Barth
2020-07-15 15:12 Sven Barth Status new => feedback
2020-07-15 15:12 Sven Barth FPCTarget => -
2020-07-15 15:12 Sven Barth Note Added: 0124039
2020-07-15 16:20 Sergey Tsukanov Note Added: 0124045
2020-07-15 16:20 Sergey Tsukanov File Added: onp_err.zip
2020-07-15 16:20 Sergey Tsukanov Status feedback => assigned
2020-07-15 16:25 Sergey Tsukanov Note Added: 0124046
2020-07-15 16:34 Sergey Tsukanov Note Added: 0124047
2020-07-15 16:34 Sergey Tsukanov File Added: onp_err_fpc304_NO_ERR.zip
2020-07-15 16:40 Sergey Tsukanov Note Edited: 0124045 View Revisions
2020-07-15 22:28 Sven Barth Note Added: 0124066
2020-07-15 22:29 Sven Barth Assigned To Sven Barth =>
2020-07-15 22:29 Sven Barth Status assigned => new
2020-07-16 04:18 Sergey Tsukanov Note Added: 0124071
2020-07-16 04:30 Sergey Tsukanov Note Edited: 0124071 View Revisions
2020-07-16 04:33 Sergey Tsukanov Note Edited: 0124071 View Revisions
2020-07-16 07:37 Sven Barth Note Added: 0124072
2020-07-17 10:51 Sergey Tsukanov Note Added: 0124119
2020-07-31 17:43 Sven Barth Assigned To => Sven Barth
2020-07-31 17:43 Sven Barth Status new => assigned
2020-07-31 17:56 Sven Barth Status assigned => resolved
2020-07-31 17:56 Sven Barth Resolution open => fixed
2020-07-31 17:56 Sven Barth Fixed in Version => 3.3.1
2020-07-31 17:56 Sven Barth Fixed in Revision => 45974
2020-07-31 17:56 Sven Barth Note Added: 0124437