var
pc :pchar;
I: Integer;
begin
getmem(pc, 2);
StrPCopy(pc, 'AA');
I := 0;
while pc[I] <> #0 do
begin
ShowMessage(pc[I]);
Inc(I);
end;
FreeMem(pc)
end;
//上面的代码是正常的, 但下面的代码是有问题的.
//请各位指点一二
var
pc :pchar;
I: Integer;
begin
getmem(pc, 2);
pc ;= pchar('AA');
I := 0;
while pc[I] <> #0 do
begin
ShowMessage(pc[I]);
Inc(I);
end;
FreeMem(pc)
end;
pc :pchar;
I: Integer;
begin
getmem(pc, 2);
StrPCopy(pc, 'AA');
I := 0;
while pc[I] <> #0 do
begin
ShowMessage(pc[I]);
Inc(I);
end;
FreeMem(pc)
end;
//上面的代码是正常的, 但下面的代码是有问题的.
//请各位指点一二
var
pc :pchar;
I: Integer;
begin
getmem(pc, 2);
pc ;= pchar('AA');
I := 0;
while pc[I] <> #0 do
begin
ShowMessage(pc[I]);
Inc(I);
end;
FreeMem(pc)
end;
pc := 'AA';
你在试试
其实错误的地方是在释放内存的时候.
pc := pchar('AA');
pc :pchar;
I: Integer;
info:string;
begin
getmem(pc, 2);
info:=info+inttostr(integer(pc))+#13;
pc := pchar('AA'); //你上面de代码为 pc ;= pchar('AA'); 是打错了吧^_^
{
此处pc已不在指向getmem(pc,2)所得到的地址了
而是指向有系统分配的存放 'AA' 的地址了,
而这块地址不应 由用户释放,所以出错了!!!
还有,原来 getmem(pc, 2) 分配的地址也可能没被释放
你可以单步 监视 pc 的值 看看,很清楚!!!
}
info:=info+inttostr(integer(pc))+#13;
ShowMessage(info);//两个地址不同啊
I := 0;
while pc[I] <> #0 do
begin
ShowMessage(pc[I]);
Inc(I);
end;
FreeMem(pc)
end;
pc :pchar;
I: Integer;
info:string;
begin
getmem(pc, 2);
info:=info+inttostr(integer(pc))+#13;
pc := pchar('AA'); //你上面de代码为 pc ;= pchar('AA'); 是打错了吧^_^
{
此处pc已不在指向getmem(pc,2)所得到的地址了
而是指向有系统分配的存放 'AA' 的地址了,
而这块地址不应 由用户释放,所以出错了!!!
还有,原来 getmem(pc, 2) 分配的地址也可能没被释放
你可以单步 监视 pc 的值 看看,很清楚!!!
}
info:=info+inttostr(integer(pc))+#13;
ShowMessage(info);//两个地址不同啊
I := 0;
while pc[I] <> #0 do
begin
ShowMessage(pc[I]);
Inc(I);
end;
FreeMem(pc)而这块地址不应 由用户释放,所以出错了!!!
end;