【发布时间】:2015-09-30 06:26:15
【问题描述】:
我正在尝试使用来自
的 Video Capture SDK在我的 Delphi 应用程序中。他们提供的唯一真正帮助是如何导入他们的类型库!我成功地做到了这一点,并且在我的项目中有一个 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 向我展示 Microsoft 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;
...
所以现在,我真的不知道该怎么做?
更新
将问题中的 item[0] 更正为 item[i]。在 IDE 中右键单击 item[i] 并选择 Find Declaration 带我到
type
IVideoDeviceCollection = interface(IDispatch)
...
property Item[index: Integer]: IVideoDevice read Get_Item;
...
end;
【问题讨论】:
-
未经检查的强制转换通常很糟糕。你怎么知道
VideoCaptureUtils.Videodevices.Item[0]真的是TVideoDevice类型?为什么要使用索引0?VideoCaptureUtils.Videodevices.Item[i]是什么类型?