Unit1function SendMsgExEx(Mobiles:Pchar;SM_Content:String;UserCount:Integer;ServiceType:String;FeeCode:String):integer;
var
................
sDestAddrs:Pchar;
iRet:integer;
sMobile:String;
begin
..........
sDestAddrs:=StrAlloc(21*UserCount-1);
sFeeAddr:=StrAlloc(21*UserCount-1);
sFeeAddr:=Mobiles;
sFeeCode:=Pchar(FeeCode);
byUserNum:=UserCount;
sDestAddrs:=Mobiles;
try
iRet:=SubmitAExEx(OrgTON,OrgNPI,OrgAddr,DestTON,DestNPI,DestAddr,
PRI,RD,RP,SRR,MR,DCS,PID,Schedule,Expire,Default_ID,UDHI,
UDLen,UserData,sServiceType,@byMsgID,byPKTotal,byPKNumber,
byMsgLevel,byFeeUserType,sSPID,sFeeType,sFeeAddr,sFeeCode,
byUserNum,sDestAddrs,@SM_ID,@FCS);
Finally
SendMsgExEx:=iRet;
//StrDispose(sDestAddrs); //当添加该句时,运行时总是地址报错
//StrDispose(sFeeAddr); //当添加该句时,运行时总是地址报错
end;
end;
Unit2procedure TFrmTest.BtnSendClick(Sender: TObject);
var vMobileList:TStringList;
vPMobile:Pchar;
Ret:Integer;
begin
vMobileList:=TStringList.Create;
if EdtMobile1.Text<>'' then
vMobileList.Add(EdtMobile1.Text);
if EdtMobile2.Text<>'' then
vMobileList.Add(EdtMobile2.Text); vPMobile:=StrAlloc(21*vMobileList.Count-1);
if (vMobileList.Count > 0) and (MemoMsg.Text <> '' ) then
begin
vPMobile:=FunctionUnit.PMobiles(vMobileList);
Ret:=FunctionUnit.SendMsgExEx(vPMobile,Trim(MemoMsg.Text),vMobileList.Count,'ZC1','750');
if Ret = 0 then
ShowMessage('发送成功! 反馈代码:'+IntToStr(Ret))
else
ShowMessage('发送失败! 反馈代码:'+IntToStr(Ret));
end
else
showMessage('请输入完整参数');
StrDispose(vPMobile);
vMobileList.Free;
end;当我执行BtnSendClick时,正常弹出对话框:'发送成功! 反馈代码.."
但是当我点击确定后就出现 'Invalid Pointer operation'.
应该是指针的问题.
当添加 StrDispose(sFeeAddr); 句时,运行时也总是地址报错 .怎么解决?
var
................
sDestAddrs:Pchar;
iRet:integer;
sMobile:String;
begin
..........
sDestAddrs:=StrAlloc(21*UserCount-1);
sFeeAddr:=StrAlloc(21*UserCount-1);
sFeeAddr:=Mobiles;
sFeeCode:=Pchar(FeeCode);
byUserNum:=UserCount;
sDestAddrs:=Mobiles;
try
iRet:=SubmitAExEx(OrgTON,OrgNPI,OrgAddr,DestTON,DestNPI,DestAddr,
PRI,RD,RP,SRR,MR,DCS,PID,Schedule,Expire,Default_ID,UDHI,
UDLen,UserData,sServiceType,@byMsgID,byPKTotal,byPKNumber,
byMsgLevel,byFeeUserType,sSPID,sFeeType,sFeeAddr,sFeeCode,
byUserNum,sDestAddrs,@SM_ID,@FCS);
Finally
SendMsgExEx:=iRet;
//StrDispose(sDestAddrs); //当添加该句时,运行时总是地址报错
//StrDispose(sFeeAddr); //当添加该句时,运行时总是地址报错
end;
end;
Unit2procedure TFrmTest.BtnSendClick(Sender: TObject);
var vMobileList:TStringList;
vPMobile:Pchar;
Ret:Integer;
begin
vMobileList:=TStringList.Create;
if EdtMobile1.Text<>'' then
vMobileList.Add(EdtMobile1.Text);
if EdtMobile2.Text<>'' then
vMobileList.Add(EdtMobile2.Text); vPMobile:=StrAlloc(21*vMobileList.Count-1);
if (vMobileList.Count > 0) and (MemoMsg.Text <> '' ) then
begin
vPMobile:=FunctionUnit.PMobiles(vMobileList);
Ret:=FunctionUnit.SendMsgExEx(vPMobile,Trim(MemoMsg.Text),vMobileList.Count,'ZC1','750');
if Ret = 0 then
ShowMessage('发送成功! 反馈代码:'+IntToStr(Ret))
else
ShowMessage('发送失败! 反馈代码:'+IntToStr(Ret));
end
else
showMessage('请输入完整参数');
StrDispose(vPMobile);
vMobileList.Free;
end;当我执行BtnSendClick时,正常弹出对话框:'发送成功! 反馈代码.."
但是当我点击确定后就出现 'Invalid Pointer operation'.
应该是指针的问题.
当添加 StrDispose(sFeeAddr); 句时,运行时也总是地址报错 .怎么解决?
解决方案 »
- 新手上路。Delphi过滤数据库查询结果的问题。望指教。
- delphi导出WORD文档左对齐语言
- 关于kfc排班!
- 高手帮忙!如何设置DXtreelist为它的行数自动加(按需要加)
- 奇怪的現象,為什麼在datetimepicker的onchange事件中的代碼會執行兩次?
- 请问EasyTable的Filter不支持字段中文名称吗?
- 如何将DFM文件转换成XML文件。
- 请问如何分出我去访问网页时各种类型的文件?
- !!!!!!!我如何发送 Ctrl +W 给另一个程序窗口
- 菜問題,BDE怎邊接SQL SERVE數據庫,可不通過odbc嗎?
- 怎样用delphi修改sql中的临时表的内容
- 给小弟推荐几个好的流程图的制作控件,如ExpressFlowChart控件
'''''''
sDestAddrs:=Mobiles;
你分配了两次内存,看清楚了;
你分配了两次内存,看清楚了;
Unit1function SendMsgExEx(Mobiles:Pchar;SM_Content:String;UserCount:Integer;ServiceType:String;FeeCode:String):integer;
var
................
sDestAddrs:Pchar;
iRet:integer;
sMobile:String;
begin
..........
sFeeAddr:=Mobiles;
sFeeCode:=Pchar(FeeCode);
byUserNum:=UserCount;
sDestAddrs:=Mobiles;
try
iRet:=SubmitAExEx(OrgTON,OrgNPI,OrgAddr,DestTON,DestNPI,DestAddr,
PRI,RD,RP,SRR,MR,DCS,PID,Schedule,Expire,Default_ID,UDHI,
UDLen,UserData,sServiceType,@byMsgID,byPKTotal,byPKNumber,
byMsgLevel,byFeeUserType,sSPID,sFeeType,sFeeAddr,sFeeCode,
byUserNum,sDestAddrs,@SM_ID,@FCS);
Finally
SendMsgExEx:=iRet;
StrDispose(sDestAddrs
end;
end;
Unit2procedure TFrmTest.BtnSendClick(Sender: TObject);
var vMobileList:TStringList;
vPMobile:Pchar;
Ret:Integer;
begin
vMobileList:=TStringList.Create;
if EdtMobile1.Text<>'' then
vMobileList.Add(EdtMobile1.Text);
if EdtMobile2.Text<>'' then
vMobileList.Add(EdtMobile2.Text);
if (vMobileList.Count > 0) and (MemoMsg.Text <> '' ) then
begin
vPMobile:=FunctionUnit.PMobiles(vMobileList);
Ret:=FunctionUnit.SendMsgExEx(vPMobile,Trim(MemoMsg.Text),vMobileList.Count,'ZC1','750');
if Ret = 0 then
ShowMessage('发送成功! 反馈代码:'+IntToStr(Ret))
else
ShowMessage('发送失败! 反馈代码:'+IntToStr(Ret));
end
else
showMessage('请输入完整参数');
vMobileList.Free;
end;
Unit1function SendMsgExEx(Mobiles:Pchar;SM_Content:String;UserCount:Integer;ServiceType:String;FeeCode:String):integer;
var
................
sDestAddrs:Pchar;
iRet:integer;
sMobile:String;
begin
..........
sFeeAddr:=Mobiles;
sFeeCode:=Pchar(FeeCode);
byUserNum:=UserCount;
sDestAddrs:=Mobiles;
try
iRet:=SubmitAExEx(OrgTON,OrgNPI,OrgAddr,DestTON,DestNPI,DestAddr,
PRI,RD,RP,SRR,MR,DCS,PID,Schedule,Expire,Default_ID,UDHI,
UDLen,UserData,sServiceType,@byMsgID,byPKTotal,byPKNumber,
byMsgLevel,byFeeUserType,sSPID,sFeeType,sFeeAddr,sFeeCode,
byUserNum,sDestAddrs,@SM_ID,@FCS);
Finally
SendMsgExEx:=iRet;
StrDispose(sDestAddrs)
end;
end;
Unit2procedure TFrmTest.BtnSendClick(Sender: TObject);
var vMobileList:TStringList;
vPMobile:Pchar;
Ret:Integer;
begin
//其中vPMobile变量的值是来自 添加手机号码集函数的(Pchar型)
vMobileList:=TStringList.Create;
if EdtMobile1.Text<>'' then
vMobileList.Add(EdtMobile1.Text);
if EdtMobile2.Text<>'' then
vMobileList.Add(EdtMobile2.Text);
if (vMobileList.Count > 0) and (MemoMsg.Text <> '' ) then
begin
vPMobile:=FunctionUnit.PMobiles(vMobileList);
Ret:=FunctionUnit.SendMsgExEx(vPMobile,Trim(MemoMsg.Text),vMobileList.Count,'ZC1','750');
if Ret = 0 then
ShowMessage('发送成功! 反馈代码:'+IntToStr(Ret))
else
ShowMessage('发送失败! 反馈代码:'+IntToStr(Ret));
end
else
showMessage('请输入完整参数');
vMobileList.Free;
end;再补充一点:{-------------------添加手机号码集-----------------}
function PMobiles(MobileList:TStringList):Pchar;
Var m,n,CountDest,MemCount,tempID:Integer;
tempMobileAdd:String[11];
tempMobileListAdd:Pchar;
begin
CountDest:=MobileList.Count;
MemCount:=21*CountDest - 1;
tempID:=0;
tempMobileListAdd:=StrAlloc(MemCount);
for m:=0 to CountDest-1 do
begin
tempMobileAdd:=MobileList.Strings[m];
for n:=1 to 21 do
begin
if n<=11 then
tempMobileListAdd[tempID]:=tempMobileAdd[n]
else
tempMobileListAdd[tempID]:=#0;
tempID:=tempID + 1;
end;
end;
Result:=tempMobileListAdd;
end;
就是在发送短信的时候出错的.
for m:=0 to CountDest-1 do
begin
tempMobileAdd:=MobileList.Strings[m];
for n:=1 to 21 do
begin
if n<=11 then
tempMobileListAdd[tempID]:=tempMobileAdd[n]
else
tempMobileListAdd[tempID]:=#0;
tempID:=tempID + 1;
end;
end;
Result:=tempMobileListAdd;
///什么时候释放呢?
for m:=0 to CountDest-1 do
begin
tempMobileAdd:=MobileList.Strings[m];
for n:=1 to 21 do
begin
if n<=11 then
tempMobileListAdd[tempID]:=tempMobileAdd[n]
else
tempMobileListAdd[tempID]:=#0;
tempID:=tempID + 1;
end;
end;
Result:=tempMobileListAdd;
STRDISPOSE(TMP)
加了这句:StrDispose(tempMobileListAdd),在调用
PMobiles(MobileList:TStringList):Pchar函数后内存已经别释放了.
这时调用SendMsgExEx函数时发送手机的号码就是空的.我是在SendMsgExEx函数发送后就释放内存.在SendMsgExEx函数内部释放!
strcopy(result,tempMobileListAdd);
StrDispose(tempMobileListAdd);我先测试!非常谢谢你!!
PMobiles(MobileList:TStringList):Pchar;
begin
....
strcopy(result,tempMobileListAdd);
StrDispose(tempMobileListAdd);
end;
TFrmTest.BtnSendClick
begin
StrDispose(sDestAddrs);
end;
出错语句:Ret:=FunctionUnit.SendMsgExEx(vPMobile,Trim (MemoMsg.Text),vMobileList.Count,'ZC1','750');
测试2:
strcopy(result,tempMobileListAdd);
出错语句:Ret:=FunctionUnit.SendMsgExEx(vPMobile,Trim (MemoMsg.Text),vMobileList.Count,'ZC1','750');
测试1:
PMobiles(MobileList:TStringList):Pchar;
begin
....
strcopy(result,tempMobileListAdd);
StrDispose(tempMobileListAdd);
end;
TFrmTest.BtnSendClick
begin
StrDispose(sDestAddrs);
end;
出错语句:Ret:=FunctionUnit.SendMsgExEx(vPMobile,Trim (MemoMsg.Text),vMobileList.Count,'ZC1','750');
测试2:
strcopy(result,tempMobileListAdd);
出错语句:Ret:=FunctionUnit.SendMsgExEx(vPMobile,Trim (MemoMsg.Text),vMobileList.Count,'ZC1','750');