To lubj:
同意929和kxy的意见.
在Delphi中, String的类型有些奇怪. 虽然它也是个指针,但是,除了字符信息外, 还有其他附加信息, 如长度, 引用计数等. 请看下面内容:
function GetStrAllocSize(const S: string): Longint;//字符串长度,相当于Length函数
var
P: ^Longint;
begin
P := Pointer(S); // pointer to string structure
Dec(P, 3); // 12-byte negative offset
Result := P^ and not $80000000 shr 1; // ignore bits 0 and 31
end;
function GetStrRefCount(const S: string): Longint;//字符串的引用计数, 若为0, 该String将被释放掉.
var
P: ^Longint;
begin
P := Pointer(S);
Dec(P, 2);
Result := P^;
end;
我的代码与以下内容有点象:
function getvalue(out aa:string):boolean;
begin
try
form1:=Tform1.create(nil);
//将aa赋给某一对象
form1.showmodal;
if form1.modalresult=mrok then begin
aa:=edit1.text;
result:=true;
end
else
result:=false;
except
result:=false;
//报错
end;
end;