有一段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下正常使用.

解决方案 »

  1.   


    szDeviceName: array[0..80] of AnsiChar;
    szDeviceVersion: array[0..80] of AnsiChar;
      

  2.   

    首先,要確認capGetDriverDescription是否有unicode版本的,看看pas中是如何引入的;
    其次,若有unicode版本的,看是否需要修改函數引入聲明。若以上說明,都不需修改,則只需修改S:= String(szDeviceName)+String(szDeviceVersion);若沒有unicode版本,則還要加上1樓的聲明修改
      

  3.   

    有一段GetCapDevice函数,是获取当前的摄像头如下: 
    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; 
      

  4.   

    用过1楼的
    szDeviceName: array[0..80] of AnsiChar;
    szDeviceVersion: array[0..80] of AnsiChar;这样的更正方法,但不能编译.用过2楼的:
    S:= String(szDeviceName)+String(szDeviceVersion); 
    返回乱码.3楼的方式改写后,返回乱码的szDeviceName.
      

  5.   

    function capGetDriverDescription; external AVICAP32 name 'capGetDriverDescriptionA';capGetDriverDescription是从AVICAP32.dll中引入的.
      

  6.   

    你现在的问题就是两个版本的编码方式不一样,2010中采用unicode编码,char,string,pchar都是unicode的,char的长度是2,而之前的版本char的长度是1
      

  7.   

    找到原因了!把这个'capGetDriverDescriptionA'
    改成'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;
      

  8.   

    我前面就讓你確認是否有Unicode版本的...
    也就是 capGetDriverDescriptionW
      

  9.   

    var len:integer;
        
    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]));
      

  10.   

    其实最好还是调用directX中的相关函数,我发现有些摄像头检测不到.....最后改了.谢谢楼上各位回复.这就给分.