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行,就可以了。
添加回答
举报
0/150
提交
取消