我把参数传到一个prodedure 去执行,可是出错了,我看了好几遍了,大家帮忙
第一个文件:
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