function test(a:integer):pchar;stdcall;
.......
    result:=PChar('AAA');
end;

解决方案 »

  1.   

    function test(a:integer):pchar;stdcall;
    .......
        result:="AAA";
    end;是要初始化吗?如果是的话,
    你这样试试看:
    function test(a:integer):pchar;stdcall;
    .......
      Result := PChar(AllocMem(10));
      Result:="AAA";
    end;
      

  2.   

    同意 debussy所言,切记Delphi的字符串的数据类型定义与Windows系统的不兼容现象……
      

  3.   

    同意楼上
    char和string不能同日而语,需要转化的。
      

  4.   

    result也是一个变量,它的生存期太短,返回后就被自动释放了。规范的作法应该是在调用过程中传递一个要生成的字符串缓冲区的指针,这样可以避免在函数中再申请内存。
      

  5.   

    楼上的虽然方法很多
    我都试过了
    但好象没有好的
    只有CoolSlob的还可以
    但他这样VB读出来的内存中所分配的地址中所有字符串啦
    又没有更好的
      

  6.   

    function getstr(var p:pchar):pchar;   //用变量参数,加关键字var
    begin
    p:='aaa';
    //result:=p; 直接在源程序中引用p就行了,甚至可以不用返回值result这一句。
    end;procedure TForm1.Button1Click(Sender: TObject);
    var a:pchar;
    begin
    a:='bbb';
    getstr(a);
    showmessage(a);
    end;