乱写的,呵呵
var
  S: string
  P: PWideChar;
begin
  S := 'Hello world';
  P := PWideChar(PChar(S));
end;

解决方案 »

  1.   

    var
     S:string;
     P:pwidechar;
    begin
    S:='hello world';
    copymemory(P,@string[1],length(string));end;
      

  2.   

    pName,pPassWord,pGroup,pMemo:PWideChar;
    begin
    Result:='其它错误';
    getmem(pName,1024);
    getmem(pPassWord,1024);
    getmem(pMemo,1024);
    StringToWideChar(name,pname,1024);
    StringToWideChar(Password,pPassWord,1024);
    StringToWideChar(Memo,pMemo,1024);
    //我写的一段程序。正确运行通过。
      

  3.   

    freemem(parm_err,1024);
    freemem(pName,1024);
    freemem(pPassWord,1024);
    freemem(pMemo,1024);
    //删除pwidechar所占用的空间?
      

  4.   

    var
      s,s1: string;
      pw: PWideChar;
    begin
      s:='hello world';
      GetMem(pw,2*length(s)+2);
      pw:=StringToWideChar(s,pw,length(s)+2);
      s1:=WideCharToString(pw);
      edit1.Text:=s1;
      freemem(pw);
    end;
      

  5.   

    我在用API碰到PCHAR类型时,如直接定义其类型,往往会出错。我的解决办法是:定义CHAR类型的数组,你不妨可以一试。
      

  6.   

    标准做法:
    var
      s:sting;
      pwc:PWidechar;
      len:integer;
    begin
      s:='abcdefg';
      len:=length(s)+1;
      pwc:=AllocMem(len*sizeof(widechar));
      stringtowidechar(s,pwc,len);
      showmessage(widechartostring(pwc));
      FreeMem(pwc);
    end;
      
      
      

  7.   

    大家对STRINGTOWIDECHAR函数有理解上的错误。
    STRINGTOWIDECHAR(S,PW,此处应为PW的空间大小除以2:也就是length(s)+1。)
      
      

  8.   

    不好意思,我试了各位的答案,都是正确的,只好分别给点分了,谢谢大家帮助,另外,可不可以帮我看看http://www.csdn.net/expert/topic/195/195718.shtm,再次谢谢!