您可以在这里快速查找:


 
您的位置: 编程学习 > delphi教程 > 200602
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

string 与 PChar

imustworkhard
来自Delphi Help  关键字String to PChar conversions
长字符串转换到PChar不是自动的。他们之间的不同点导致他们的转换存在问题。
1,长字符串是引用计数的,而PChar不是
2,赋值给长字符串是数据的拷贝,而PChar是指向数据的指针。
3,长字符串是空止符结尾,并包含有字符串的长度。而PChar是简单的空止符结尾。( 空止符结尾指以#0结尾)

procedure my_func(x: string);
begin
    some_proc(PChar(x)); //参照第一条,这么做自己负责x的生存期
end;

function title(n: Integer): PChar;
var
  s: string;
begin
  s := Format(´title - %d´, [n]);
  Result := PChar(s); // 参照第2条,不能这么做
end;