View Issue Details

IDProjectCategoryView StatusLast Update
0038151FPCRTLpublic2020-12-06 11:51
Reporterserbod Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformWindows 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038151: ComObj property set by reference
DescriptionProperty assignment for ComObj variant in some case need special treatment (as in remarks from https://docs.microsoft.com/en-us/windows/win32/api/oaidl/nf-oaidl-idispatch-invoke).

Included path fixing assignment of another COM object to property of COM object, as in example.
Steps To Reproduce// At least two SAPI voices must be installed!
// Win7+ have 2 English voices by default

uses ComObj;

procedure TestVoice();
var
  SpVoice, SpVoicesList: Variant;
begin
  SpVoice := CreateOleObject('SAPI.SpVoice');
  SpVoicesList := SpVoice.GetVoices();
  // assign second speech voice as default voice, cause 'Member not found' error
  SpVoice.Voice := SpVoicesList.Item(1);
  SpVoice.Speak('Hello, world!');
end;
TagsNo tags attached.
Fixed in Revision47687
FPCOldBugId
FPCTarget-
Attached Files

Activities

serbod

2020-11-29 23:52

reporter  

comobj.pp.diff (1,546 bytes)   
*** C:/fpcupdeluxe/fpcsrc/packages/winunits-base/src/comobj.pp	Fri Nov 27 16:50:41 2020
--- C:/Work/ZhdunQMS/src/comobj.pp	Mon Nov 30 01:45:06 2020
***************
*** 1381,1392 ****
            case InvokeKind of
              DISPATCH_PROPERTYPUT:
                begin
!                 if (Arguments[0].VType and varTypeMask) = varDispatch then
                    InvokeKind:=DISPATCH_PROPERTYPUTREF;
                  { first name is actually the name of the property to set }
                  DispIDs^[0]:=DISPID_PROPERTYPUT;
                  DispParams.rgdispidNamedArgs:=@DispIDs^[0];
!                 inc(DispParams.cNamedArgs);
                end;
              DISPATCH_METHOD:
                { It appears that certain COM servers expect both DISPATCH_METHOD and DISPATCH_PROPERTYGET
--- 1381,1393 ----
            case InvokeKind of
              DISPATCH_PROPERTYPUT:
                begin
!                 if ((Arguments[0].VType and varTypeMask) in [varDispatch, varVariant])
!                 and ((Arguments[0].VType and varByRef) <> 0) then
                    InvokeKind:=DISPATCH_PROPERTYPUTREF;
                  { first name is actually the name of the property to set }
                  DispIDs^[0]:=DISPID_PROPERTYPUT;
                  DispParams.rgdispidNamedArgs:=@DispIDs^[0];
!                 DispParams.cNamedArgs:=1;
                end;
              DISPATCH_METHOD:
                { It appears that certain COM servers expect both DISPATCH_METHOD and DISPATCH_PROPERTYGET
comobj.pp.diff (1,546 bytes)   
comobj.pp.patch (366 bytes)   
1384c1384,1385
<                 if (Arguments[0].VType and varTypeMask) = varDispatch then
---
>                 if ((Arguments[0].VType and varTypeMask) in [varDispatch, varVariant])
>                 and ((Arguments[0].VType and varByRef) <> 0) then
1389c1390
<                 inc(DispParams.cNamedArgs);
---
>                 DispParams.cNamedArgs:=1;
comobj.pp.patch (366 bytes)   

Thaddy de Koning

2020-12-02 21:53

reporter   ~0127325

I wrote an article about that in UNDU in 1999. It may be that the interface is broken, but even then there where at least two voices. (Although I used the Parrot)
Will see if I can dig up that code again. It should not fail, but right now I am on Linux.

Sven Barth

2020-12-04 23:09

manager   ~0127348

I've fixed it slightly differently, cause not every Variant passed in should also be passed as reference (at least Delphi does not do so).

Please test and close if okay.

serbod

2020-12-06 11:51

reporter   ~0127371

It works, thanks!

Issue History

Date Modified Username Field Change
2020-11-29 23:52 serbod New Issue
2020-11-29 23:52 serbod File Added: comobj.pp.diff
2020-11-29 23:52 serbod File Added: comobj.pp.patch
2020-12-02 21:53 Thaddy de Koning Note Added: 0127325
2020-12-04 23:09 Sven Barth Assigned To => Sven Barth
2020-12-04 23:09 Sven Barth Status new => resolved
2020-12-04 23:09 Sven Barth Resolution open => fixed
2020-12-04 23:09 Sven Barth Fixed in Version => 3.3.1
2020-12-04 23:09 Sven Barth Fixed in Revision => 47687
2020-12-04 23:09 Sven Barth FPCTarget => -
2020-12-04 23:09 Sven Barth Note Added: 0127348
2020-12-06 11:51 serbod Status resolved => closed
2020-12-06 11:51 serbod Note Added: 0127371