A
acdc
Unregistered / Unconfirmed
GUEST, unregistred user!
有这样的记录:
PRecord = ^TRecord;
TRecord = packed record
Head : array[0..11] of Char;
end;
调用:
procedure TForm1.Button1Click(Sender: TObject);
var
aAry:array[0..SizeOf(TRecord)] of Char;
begin
FillChar(aAry,SizeOf(aAry),'a');
FunTest(@aAry);
end;
procedure TForm1.FunTest(pBufChar);
var
pRcdRecord;
sTmp:string;
begin
pRcd := Pointer(pBuf);
sTmp := pRcd.Head;//如果没有这条赋值语句,下面的move会出错。
Move(pRcd.Head,PChar(sTmp)^,SizeOf(pRcd.Head));
Memo1.Lines.Add(sTmp);
end;
把记录类型扩展一下:
PTBC_HEAD = ^TTBC_HEAD;
TTBC_HEAD = packed record
PckLen: array[0..3] of Char;
BizNo : array[0..1] of Char;
CmdNo : array[0..1] of Char;
SeqNo : array[0..3] of Char;
end;
PRecord = ^TRecord;
TRecord = packed record
Head : TTBC_HEAD;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
aAry:array[0..SizeOf(TRecord)] of Char;
begin
FillChar(aAry,SizeOf(aAry),'a');
FunTest(@aAry);
end;
procedure TForm1.FunTest(pBufChar);
var
pRcdRecord;
sTmp:string;
begin
pRcd := Pointer(pBuf);
sTmp := pRcd.Head.PckLen;//如果没有这条赋值语句,下面的move会出错。
Move(pRcd.Head,PChar(sTmp)^,SizeOf(pRcd.Head));
Memo1.Lines.Add(sTmp);//现在是这里会出错了。
end;
PRecord = ^TRecord;
TRecord = packed record
Head : array[0..11] of Char;
end;
调用:
procedure TForm1.Button1Click(Sender: TObject);
var
aAry:array[0..SizeOf(TRecord)] of Char;
begin
FillChar(aAry,SizeOf(aAry),'a');
FunTest(@aAry);
end;
procedure TForm1.FunTest(pBufChar);
var
pRcdRecord;
sTmp:string;
begin
pRcd := Pointer(pBuf);
sTmp := pRcd.Head;//如果没有这条赋值语句,下面的move会出错。
Move(pRcd.Head,PChar(sTmp)^,SizeOf(pRcd.Head));
Memo1.Lines.Add(sTmp);
end;
把记录类型扩展一下:
PTBC_HEAD = ^TTBC_HEAD;
TTBC_HEAD = packed record
PckLen: array[0..3] of Char;
BizNo : array[0..1] of Char;
CmdNo : array[0..1] of Char;
SeqNo : array[0..3] of Char;
end;
PRecord = ^TRecord;
TRecord = packed record
Head : TTBC_HEAD;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
aAry:array[0..SizeOf(TRecord)] of Char;
begin
FillChar(aAry,SizeOf(aAry),'a');
FunTest(@aAry);
end;
procedure TForm1.FunTest(pBufChar);
var
pRcdRecord;
sTmp:string;
begin
pRcd := Pointer(pBuf);
sTmp := pRcd.Head.PckLen;//如果没有这条赋值语句,下面的move会出错。
Move(pRcd.Head,PChar(sTmp)^,SizeOf(pRcd.Head));
Memo1.Lines.Add(sTmp);//现在是这里会出错了。
end;