Link to home
Start Free TrialLog in
Avatar of azsd
azsd

asked on

how to use dynamic array in packed record like fixed array?

Hi,I have a packed record here:

=========================
tagCngpTLV = packed record
    Tag:WORD;
    Length:WORD;
    Value:Array of Byte;
    Reserve:Array[0..7] of Byte;
end;
=========================
I have an record like this:
CngpTLV1:tagCngpTLV
Tag:$0001,
Length:$0006;
Value:$FF,FF,FF,FC,00,00
Reserve:$00,00,00,00,00,00,00,00

if I use CngpTLV1 as a buffer to insert it into a stream,the data in Value postion became a ^Array pointer.
How Can I use it like an
    Tag:WORD;
    Length:WORD;
    Value:Array[0..5] of Byte;
    Reserve:Array[0..7] of Byte;
record?

in fact I have more complex record struct so I can't use another buffer and calc the each items' postion&size then copy into it one by one.
ASKER CERTIFIED SOLUTION
Avatar of robert_marquardt
robert_marquardt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of azsd
azsd

ASKER

sorry,I haven't describe my problem clearly.

I have aready alloced 6 byte Value by setlength and Move()-ed some datas in record,
I wan't to get an datastream like this for use:

$01,00;$06,00;$FF,FF,FF,FC,00,00;$00,00,00,00,00,00,00,00

and now I use the @CngpTLV1 as an buffer pointer,
the data in memory like

$01,00;$06,00;$28,00,60,00;$00,00,00,00,00,00,00,00

I had to use code like:
var
  newbuf:array of byte;
begin
  //CngpTLV1 ready
  SetLength(newbuf,sizeof(CngpTLV1)-Sizeof(CngpTLV1.value)+CngpTLV1.Length);
  FillChar(newbuf,Length(newbuf),0);
  Move(CngpTLV1,newbuf[0],sizeof(CngpTLV1.Tag)+Sizeof(CngpTLV1.Length));
  Move(CngpTLV1.Value[0],newbuf[sizeof(CngpTLV1.Tag)+Sizeof(CngpTLV1.Length)],CngpTLV1.Length);
  Move(CngpTLV1.Reserve,newbuf[sizeof(CngpTLV1.Tag)+Sizeof(CngpTLV1.Length)+CngpTLV1.Length],sizeof(CngpTLV1.Reserve));
  //Send(clientsocket, newbuf[0],Length(newbuf),0);
  //or save the buf to disk
end;

In reality application,there some more then 40 member record with about 6,7 dynamic length,
I want to kick my screen usually.

I tried to use follow codes:

    Tag:WORD;
    Length:WORD;
    Value:Array[0..Length-1] of Byte;
    Reserve:Array[0..7] of Byte;

sure I was shamely get grammer error.
Avatar of azsd

ASKER

quote:
I want to get an datastream like this for use,not "wan't"