Delphi 用 Import Type Library 导入一个VB写的Com DLL后,自动将dll中所有string类型转换成WideString了,在实际使用过程中遇到了问题:
[Delphi Code]uses TestDLL_TLB; //导入Com后自动生成的单元。
var Test:Class1 
begin
   with FileDialog1 do //对话框选择文件,用的是Delphi 2010,支持unicode字符。
   begin
       showMessage(FileName); //测试用
       Test:=CoClass1.Create;
       Test.TestShow(FileName,Form1.Edit1.Text); 
       Test:=Nil;     
   end;
end;[VB Com Code]Public Function TestShow(Byval strFileName as string,ByRef strText as string) as long
   '读取StrFileName,然后返回StrText
End Function
具体表现在:
如果从繁体XP系统,选择一个带简体路径的文件(内容是简体中文), Delphi中ShowMessage出来的路径名是正确的,但按默认的WideString方式传入DLL后,Eidt1中返回的内容为空。
此时,如果将路径名改成繁体或英文路径,则Edit1能显示出文件中的简体。Delphi中的WideString不是Unicode编码吗,如何处理才能显示出带简体路径的文件内容?另外,网上说Delphi在字符传递的时候最好不要用String和WideString,而用PChar/PWideChar。
如果要更改传递类型,是不是要手动将 TestDLL_TLB 单元中的WideString全部换成PWideChar,VB端能直接读取吗??因为刚刚从VB转入Delphi,请各位指教,不胜感谢!

解决方案 »

  1.   

    楼主VB中的函数第二个参数是传址引用,所以在DELPHI中不应该直接将控件的属性作为参数使用。uses TestDLL_TLB; //导入Com后自动生成的单元。
    var Test:Class1;
    var S: WideString;
    begin
      with FileDialog1 do //对话框选择文件,用的是Delphi 2010,支持unicode字符。
      begin
      s := Form1.Edit1.Text;
      showMessage(FileName); //测试用
      Test:=CoClass1.Create;
      Test.TestShow(FileName,s);  
      Test:=Nil;   
      end;
    end;
      

  2.   

    谢谢chris_mao,我将代码改成:uses TestDLL_TLB; //导入Com后自动生成的单元。
    var Test:Class1;
    var S: WideString;
    begin
      with FileDialog1 do 
      begin
      showMessage(FileName); 
      Test:=CoClass1.Create;
      Test.TestShow(FileName,S]); 
      Eidt1.text := S;  //这里依然显示不出来。而换成英文路径就可以了
      Test:=Nil;   
      end;
    end;
      

  3.   

    自己的疏忽,dll内部读取文件时用了ANSI版的API,改成Unicode版本问题解决,再次感谢