提示错误:Invalid pointer operation.何解?

dll函数代码如下:
function BaseEncode(ss:PChar;Res:PChar):Integer;stdcall;
begin
StrCopy(Res,ss);
StrCat(Res,'_00000');
Result := StrLen(Res);
end;
exports
BaseEncode;

调用代码如下:
function BaseEncode(ss:Pchar; Res:PChar):Integer;stdcall;
external '../ChangCode/changecode.dll';

procedure TForm1.Button2Click(Sender: TObject);
var
ss:PChar;
Res:PChar;
Num:Integer;
begin
ss := 'good!';
Res := StrAlloc(80);
Num := BaseEncode(PChar(ss), PChar(Res));
Edit1.Text := Res;
Edit2.Text := IntToStr(Num);
StrDispose(ss);
StrDispose(Res);
end;


但结果可以正确显示。
是这个问题
Edit1.Text := string(Res); 
改了就可以。
小弟一直用JAVA,DELPHI刚开始用,谢谢啦。

慕标琳琳
浏览 514回答 1
1回答

呼啦一阵风

Num := BaseEncode(PChar(ss), PChar(Res));是这一行出现问题吗?试着修改为:Num := BaseEncode(ss, Res); 如果是Edit1.Text := Res;这一行,则修改为 Edit1.Text := string(Res); 你说明白啊,哪个地方报错? StrDispose, 这个你不能使用,DescriptionStrDispose is provided for backward compatibility only. StrDispose disposes of a string on a heap that was previously allocated with StrAlloc or StrNew. If Str is nil, StrDispose does nothing.需要和StrAlloc或StrNew一起使用。 去掉最后2行,就可以了。
打开App,查看更多内容
随时随地看视频慕课网APP