我试图在我的Delphi应用程序使用视频采集SDK从如何在Delphi XE2中将IDispatch转换为TOleServer?
。他们提供的唯一真正的帮助是如何导入他们的类型库!我做了这个成功,并在我的项目中有一个DTKVideoCapLib_TLB.pas。
我明白了这一点。
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
s: String;
VideoCaptureUtils: TVideoCaptureUtils;
VideoDevice: TVideoDevice;
begin
VideoCaptureUtils := TVideoCaptureUtils.Create(Self);
for i := 0 to VideoCaptureUtils.VideoDevices.Count - 1 do
begin
s := VideoCaptureUtils.VideoDevices.Item[i].Name;
ShowMessage(s);
VideoDevice := TVideoDevice(VideoCaptureUtils.Videodevices.Item[i]);
end;
ShowMessage好心显示我微软的LifeCam VX-800
所以我必须做一些正确的事情,但下一行后,在调试器,VideoDevice是nil
。
看在DTKVideoCapLib_TLB.pas,我看到了下面
TVideoDevice = class(TOleServer)
private
FIntf: IVideoDevice;
function GetDefaultInterface: IVideoDevice;
protected
...
IVideoDevice = interface(IDispatch)
['{8A40EA7D-692C-40EE-9258-6436D1724739}']
function Get_Name: WideString; safecall;
...
所以,现在,我真的没有关于如何执行该方法的想法?
更新
更正项[0],在问题项[I]。在IDE中的项目[i]和选择查找宣言右键单击需要我
type
IVideoDeviceCollection = interface(IDispatch)
...
property Item[index: Integer]: IVideoDevice read Get_Item;
...
end;
未经检查的强制类型转换通常是不好的。你怎么知道'VideoCaptureUtils.Videodevices.Item [0]'确实属于'TVideoDevice'类型?为什么使用索引'0'? 'VideoCaptureUtils.Videodevices.Item [i]'是什么类型? –