var
  test: string[255];
begin
  Test := '这是一个测试';
  Application.MessageBox(test,'测试');
end;编译时调用MessageBox说类型不区配,应如何做?

解决方案 »

  1.   

    Application.MessageBox(pchar(test),'测试');
      

  2.   

    var
      test: string;
    begin
      Test := '这是一个测试';
      Application.MessageBox(pchar(test),'测试');
    end;
      

  3.   

    var
      test: string;
    begin
      Test := '这是一个测试';
      Application.MessageBox(test,'测试',MB_OK);
    end;
      

  4.   

    看错了,你用的是ShortString,要这样PChar(String(test))Application.MessageBox(PChar(String(test)), '测试', MB_OK);
      

  5.   

    var
      test: string[255];
    声明的是一个shortstring,而shortstring不是以null结尾的字符串,所以直接用pchar()是不行的.如果在定义时特地指定了长度(最大在2 5 5个字符内),那么总是shortstring类型的
    应该声明为test:string.这是Pascal缺省的字符串类型,由AnsiChar 字符组成,其长度没有限制,同时与null结束的字符串相兼容。
      

  6.   

    var
      test: string[255];
    begin
      Test := '这是一个测试';
      Application.MessageBox(PChar(test),'测试',0);
    end;