为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕标琳琳 2022-12-16 18:14:50
dll函数代码如下:function BaseEncode(ss:PChar;Res:PChar):Integer;stdcall;beginStrCopy(Res,ss);StrCat(Res,'_00000');Result := StrLen(Res);end;exportsBaseEncode;调用代码如下:function BaseEncode(ss:Pchar; Res:PChar):Integer;stdcall;external '../ChangCode/changecode.dll';procedure TForm1.Button2Click(Sender: TObject);varss:PChar;Res:PChar;Num:Integer;beginss := '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刚开始用,谢谢啦。
查看完整描述

1 回答

?
呼啦一阵风

TA贡献1802条经验 获得超6个赞

Num := BaseEncode(PChar(ss), PChar(Res));是这一行出现问题吗?试着修改为:Num := BaseEncode(ss, Res); 
如果是Edit1.Text := Res;这一行,则修改为 Edit1.Text := string(Res); 

你说明白啊,哪个地方报错? 
StrDispose, 这个你不能使用,
Description

StrDispose 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行,就可以了。

查看完整回答
反对 回复 2022-12-18
  • 1 回答
  • 0 关注
  • 279 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信