我把参数传到一个prodedure 去执行,可是出错了,我看了好几遍了,大家帮忙

wangguodong 2004-05-05 08:19:41
第一个文件:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,smpp_proUit, IdWinsock;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

ptest = ^TTest;
TTest = packed record
a :longword;
b :byte;
c :array[0..20] of char;
end;
procedure setTest(var test:TTest;
a:longword;
b:byte;
c:string);


var
Form1: TForm1;

implementation

{$R *.dfm}

procedure setTest( var test:TTest;
a:longword;
b:byte;
c:string);
begin
test.a := a;
test.b := b;
fillchar(test.c,sizeof(test.c),0);
StrPCopy(test.c,c);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
pObj:pSmpp_submit;
sequenceId:LongWord;
len:LongWord;
strMsg:string;
begin
new(pObj);
sequenceId := 99;
len := sizeof(Tsmpp_submit);
strMsg := 'test';
assemble_Submit( pObj^,
len,
SMPP_SUBMIT,
44,
'fdas',
'138',
140,
strMsg);
end;




end.
第二个文件:
unit smpp_proUit;

interface
uses
IdWinsock , SysUtils ,Dialogs;

const
Content_len = 140;
SMPP_CONNECT: LongWord = $00000001;
SMPP_CONNECT_RESP: LongWord = $80000001;
SMPP_SUBMIT: LongWord = $00000004;
SMPP_SUBMIT_RESP: LongWord = $80000004;
SMPP_DELIVER: LongWord = $00000005;
SMPP_DELIVER_RESP: LongWord = $80000005;
SMPP_ACTIVE_TEST: LongWord = $00000008;
SMPP_ACTIVE_TEST_RESP: LongWord = $80000008;
Result1:LongWord =$00000000;
type
psmpp_Head = ^Tsmpp_Head;
Tsmpp_Head = packed record
Total_Length: LongWord; //消息总长度(含消息头及消息体)
Command_ID: LongWord; //命令或响应类型
Sequence_ID: LongWord; //消息流水号,顺序累加,步长为1,循环使用(一对请求和应答消息的流水号必须相同)
end;


Psmpp_submit_body = ^Tsmpp_submit_body;
Tsmpp_submit_body = packed record
EnterPriseId : array[0..19] of char;
Dest : array[0..19] of char;
Content_len : byte;
Content: array[0..Content_len-1] of char;
end;

Psmpp_submit = ^Tsmpp_submit;
Tsmpp_submit = packed record
head : Tsmpp_Head;
body : Tsmpp_submit_body;
end;



procedure assemble_Submit(var SmppObj:Tsmpp_submit;
len:LongWord;
CommandID:LongWord;
SequenceID:LongWord;
EnterpriseId:string;
Dest:string;
MsgLen:byte;
Content:string);




implementation

procedure assemble_Submit( var SmppObj:Tsmpp_submit;
len:LongWord;
CommandID:LongWord;
SequenceID:LongWord;
EnterpriseId:string;
Dest:string;
MsgLen:byte;
Content:string);
begin


SMPPObj.head.Total_Length := htonl(len);
SMPPObj.head.Command_ID := htonl(CommandID);
SMPPObj.head.Sequence_ID := htonl( SequenceID);

fillchar(SMPPObj.body.EnterPriseId,sizeof(SMPPObj.body.EnterPriseId),0);
StrPCopy(SMPPObj.body.EnterPriseId,EnterpriseId);
fillchar(SMPPObj.body.Dest,sizeof(SMPPObj.body.Dest),0);
StrPCopy(SMPPObj.body.Dest,Dest);
SMPPObj.body.Content_len := MsgLen;
fillchar(SMPPObj.body.Content,sizeof(SMPPObj.body.Content),0);
StrPCopy(SMPPObj.body.Content,Content);

end;

end.

就是在这个地方出错的:
new(pObj);
sequenceId := 99;
len := sizeof(Tsmpp_submit);
strMsg := 'test';
assemble_Submit( pObj^,
len,
SMPP_SUBMIT,
44,
'fdas',
'138',
140,
strMsg);
系统的提示是:
access voiv access violation at address 00000000


...全文
33 8 点赞 打赏 收藏 举报
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wangguodong 2004-06-21
谢谢大家了
  • 打赏
  • 举报
回复
ahjoe 2004-05-09
Psmpp_submit = ^Tsmpp_submit
函数原型改为:procedure assemble_Submit(SmppObj: Psmpp_submit;
len: LongWord;
CommandID: LongWord;
SequenceID: LongWord;
EnterpriseId: string;
Dest: string;
MsgLen: byte;
Content: string);
调用的地方直接传指针。
  • 打赏
  • 举报
回复
songyangaaron 2004-05-09
不知道你是用的什么系统,什么版本,我试的时候提示的错误是:
Error on call Winsock2 library function htonl: 应用程序没有调用WSAStartup,或者WSAStartup失败。

估计是你初始化的问题吧。

我用XP+Delphi7,没有IdWinsock,只能引用IdWinsock2单元。
  • 打赏
  • 举报
回复
wangguodong 2004-05-06
我试试了,还是不行
  • 打赏
  • 举报
回复
getit911 2004-05-06
var
smppSubmitObj:Tsmpp_submit;

//self.m_ClientSocket.Socket

assemble_Submit( smppSubmitObj,
len,
SMPP_SUBMIT,
sequenceId,
m_stEnterPriseId,
strDest,
140,
strMsg);
  • 打赏
  • 举报
回复
wangguodong 2004-05-06
不行啊,我换成了如下,还是那样的错误
smppSubmitObj := pObj^;
//self.m_ClientSocket.Socket

assemble_Submit( smppSubmitObj,
len,
SMPP_SUBMIT,
sequenceId,
m_stEnterPriseId,
strDest,
140,
strMsg);
pObj^ := smppSubmitObj;
  • 打赏
  • 举报
回复
getit911 2004-05-05
直接传递记录就成了
  • 打赏
  • 举报
回复
songyangaaron 2004-05-05
内存分配的问题,看不出你第一个参数用指针类型的必要性。
  • 打赏
  • 举报
回复
相关推荐
发帖
网络通信/分布式开发
加入

1579

社区成员

Delphi 网络通信/分布式开发
申请成为版主
帖子事件
创建了帖子
2004-05-05 08:19
社区公告
暂无公告