Reputation: 2287
I am attempting to use the Video Capture SDK from
in my Delphi App. The only real help they provide, is how to import their type library! I did this succesfully and have a DTKVideoCapLib_TLB.pas in my project.
I got this far.
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 kindly displays me Microsoft LifeCam VX-800
so I must have done something right, but after the next line, in the debugger, VideoDevice is a nil
.
Looking over the DTKVideoCapLib_TLB.pas, I see the following
TVideoDevice = class(TOleServer)
private
FIntf: IVideoDevice;
function GetDefaultInterface: IVideoDevice;
protected
...
IVideoDevice = interface(IDispatch)
['{8A40EA7D-692C-40EE-9258-6436D1724739}']
function Get_Name: WideString; safecall;
...
So now, I really have no idea about how to proceed with this?
Update
Corrected item[0] to item[i] in the question. Right-click on item[i] in the IDE and selected Find Declaration takes me to
type
IVideoDeviceCollection = interface(IDispatch)
...
property Item[index: Integer]: IVideoDevice read Get_Item;
...
end;
Upvotes: 0
Views: 554
Reputation: 125708
You should use as
. Delphi will automatically attempt to obtain the desired interface for you. Something like this (untested!) should work:
var
VideoDevice: IVideoDevice; // note the type of the variable
....
VideoDevice := VideoCaptureUtils.Videodevices.Item[0] as IVideoDevice;
Your update, however, provides more detail that weren't present when I wrote my original answer. That update includes code that indicates that Videodevices
already contains IVideoDevice
, so you don't need the cast at all - you just need the proper variable declaration:
var
VideoDevice: IVideoDevice; // note the type of the variable
....
VideoDevice := VideoCaptureUtils.Videodevices.Item[i];
Upvotes: 3
Reputation: 613013
VideoCaptureUtils.Videodevices.Item[i]
has type IVideoDevice
. So you cannot cast it to TVideoDevice
.
You need to correct the type of the variable:
var
VideoDevice: IVideoDevice;
And then assign it like this:
VideoDevice := VideoCaptureUtils.VideoDevices.Item[i];
Upvotes: 1