【发布时间】:2015-06-06 01:18:37
【问题描述】:
我使用 Delphi 有一段时间了,但我正在尝试一些 COM 编程并且遇到了麻烦。如果这是一个 NewBie 问题,我深表歉意,但是在搜索了很多东西之后,我无法获取或设置 RDPEncom RDPSession 对象的属性。代码(包括几个幼稚的尝试)如下。如果我删除了试图读取属性的行,剩下的代码就可以正常工作。
如何获取和设置 RDPSession.Properties 的 PortID 属性?
uses rdpencomapi_TLB; // from JWAPI
...
myRDPSession := CoRDPSession.Create();
if VarIsNull(myRDPSession) then
begin
application.MessageBox('MsRdpSession creation failed.', 'Error');
Result := False;
Exit;
end;
try
didShare := myRDPSession.Open;
except
ShowMessage('Unable to share desktop !');
Exit;
end;
theProperty := 'PortID';
ActiveXProp := myRDPSession.Properties;
//lValues := ActiveXProp.Property_(theProperty); // method not supported
//lValues := ActiveXProp.Property(theProperty); // member not found
myRDPSession.Properties.GetProperty(lValues, myRDPSession.Properties.Property, theProperty);
{
ALL RETURN INVALID NUMBER OF PARAMETERS..
ActiveXProp.GetProperty(lValues, ActiveXProp.Property, 'PortID');
ActiveXProp.Property.GetProperty(ActiveXProp.Property, lValues, 'PortID');
ActiveXProp.Property.GetProperty(lValues, ActiveXProp, 'PortID');
ActiveXProp.Property.Get_Prop_('PortID', ActiveXProp);
ActiveXProp.Property.SetProperty('PortID', ActiveXProp);
ActiveXProp.Property.Set_Prop_('PortID', ActiveXProp);
}
ActiveXInvite := myRDPSession.Invitations.CreateInvitation('RemoteSupport', 'WePresent', '12345', 75);
...
【问题讨论】:
-
RDPSession.Properties的定义是什么? (它是如何在 IRDPSession 的源代码中声明的?)我怀疑它是Variant(这可能意味着一个 Variant 数组)或某种集合;无论哪种方式,它都是复数,这意味着有多个条目,这意味着对内容进行某种迭代。 -
Ken: TLB 单元中的 RDPSession.Properties 它是一个 IDispatch 接口,没有定义实际属性,但具有 Get_Property_ 和 Set_Property_ 函数。根据 MSDN,Get 和 Set 是获取属性的唯一方法。不幸的是,我无法以这种方式获取或设置它们。