有一段GetCapDevice函数,是获取当前的摄像头如下:
function TCapture.GetCapDevice(list:TStrings):Integer;
var
wDriverIndex: Integer;
szDeviceName: array[0..80] of Char;
szDeviceVersion: array[0..80] of Char;
s:String;
begin
wDriverIndex:=0;
while capGetDriverDescription(wDriverIndex,szDeviceName,length(szDeviceName),
szDeviceVersion,length(szDeviceVersion)) do
begin S:= szDeviceName+szDeviceVersion;//**此句产生Incompatible types错误.
list.Add(s);
Inc(wDriverIndex);
end;
Result:=wDriverIndex;//返回可用摄像头设备数
end;
Delphi2007中运行正常.
但在delphi2010中不能编译通过,显示:
[DCC Error] Capture.pas(152): E2008 Incompatible types
断点在:S:= szDeviceName+szDeviceVersion;请问这个应该如何转换为delphi2010下正常使用.
function TCapture.GetCapDevice(list:TStrings):Integer;
var
wDriverIndex: Integer;
szDeviceName: array[0..80] of Char;
szDeviceVersion: array[0..80] of Char;
s:String;
begin
wDriverIndex:=0;
while capGetDriverDescription(wDriverIndex,szDeviceName,length(szDeviceName),
szDeviceVersion,length(szDeviceVersion)) do
begin S:= szDeviceName+szDeviceVersion;//**此句产生Incompatible types错误.
list.Add(s);
Inc(wDriverIndex);
end;
Result:=wDriverIndex;//返回可用摄像头设备数
end;
Delphi2007中运行正常.
但在delphi2010中不能编译通过,显示:
[DCC Error] Capture.pas(152): E2008 Incompatible types
断点在:S:= szDeviceName+szDeviceVersion;请问这个应该如何转换为delphi2010下正常使用.
解决方案 »
- delphi idhttp控件读取验证码问题
- 急需能打开DICOM文件的程序啊
- websnap,在运行debuger时,点击那个URL,总显示出错页面,见内。如何解决?
- 怎么去掉,数据库读入memo框中输入的字符串换行时自动加的逗号?
- 工资汇总表(用RAVE5)如何做?
- 如何将显示器上某个指定区域的内容抓成BMP图像文件?
- 如何通过代码设置LISTVIEW控件的标题头的宽度?
- 我想给高分。急!急!急!急!急!急!
- 该怎么写代码来判断?
- 哪位高手有关于delphi做汉字笔顺的代码或者能做?
- 快过年了,预祝大家春节快乐!
- [求助]clientdatset 同时设置FieldKind 和DataType
szDeviceName: array[0..80] of AnsiChar;
szDeviceVersion: array[0..80] of AnsiChar;
其次,若有unicode版本的,看是否需要修改函數引入聲明。若以上說明,都不需修改,則只需修改S:= String(szDeviceName)+String(szDeviceVersion);若沒有unicode版本,則還要加上1樓的聲明修改
function TCapture.GetCapDevice(list:TStrings):Integer;
var
wDriverIndex: Integer;
szDeviceName: PChar;
szDeviceVersion: PChar;
s:PChar;
begin
wDriverIndex:=0;
GetMem(szDeviceName,80);
GetMem(szDeviceVersion,80);
GetMem(S,160);
while capGetDriverDescription(wDriverIndex,szDeviceName,length(szDeviceName),
szDeviceVersion,length(szDeviceVersion)) do
begin
StrCat(S,szDeviceName);
StrCat(S,szDeviceVersion);
list.Add(s);
Inc(wDriverIndex);
end;
Result:=wDriverIndex;//返回可用摄像头设备数
end;
szDeviceName: array[0..80] of AnsiChar;
szDeviceVersion: array[0..80] of AnsiChar;这样的更正方法,但不能编译.用过2楼的:
S:= String(szDeviceName)+String(szDeviceVersion);
返回乱码.3楼的方式改写后,返回乱码的szDeviceName.
改成'capGetDriverDescriptionW '
然后整体改写如下:
function TCapture.GetCapDevice(list:TStrings):Integer;
var
wDriverIndex: Integer;
szDeviceName: array[0..80] of wideChar;
szDeviceVersion: array[0..80] of WideChar;
s:wideString;
begin
wDriverIndex:=0;
{ GetMem(szDeviceName,80);
GetMem(szDeviceVersion,80); }
// GetMem(S,160); } while capGetDriverDescription(wDriverIndex,szDeviceName,length(szDeviceName),
szDeviceVersion,length(szDeviceVersion)) do
begin S:= widestring(szDeviceName);//+widestring(szDeviceVersion);
//StrCat(S,szDeviceName);
// StrCat(S,szDeviceVersion); list.Add(s);
Inc(wDriverIndex);
end;
Result:=wDriverIndex;//返回可用摄像头设备数
end;
也就是 capGetDriverDescriptionW
S:= szDeviceName+szDeviceVersion;改成拷贝吧
len:=strlen(@szDeviceName[0])+strlen(@szDeviceVersion[0]);
setlength(S,len);
copymemeory(pchar(s),@szDeviceName[0],strlen(@szDeviceName[0]));
copymemeory(pchar(s)+strlen(@szDeviceName[0]),@szDeviceVersion[0],sizeof(@szDeviceVersion[0]));