I wrote a function,which seperates two or more packets received in one physical packet.However,the compiler doesn't appreciate my effort. The size of every packet is in the first two bytes of the header of the packet,which is 6 bytes.so one real packet = it's first two bytes + 6.That's how I find if there is more than one packet.
procedure SeparatePackets(packet:pointer;size:word; out Result:Array of pointer; out number:byte);
var position:byte; //position
begin
position:= 0;
number:= 0;
SetLength(Result,0); //<< ERROR
while(PWord(Cardinal(packet) + position)^ + 6 <> size) do //while the first two bytes + 6(packet header)
begin
SetLength(Result,Length(Result) + 1); //inc the length << ERROR
Result[number] := Cardinal(packet) + position;
position := Result[number] + PWord(Cardinal(packet) + position)^ + 6;
inc(number);
end;
end;
I marked the compile-time errors with '<< ERROR'. The error is one - 'Incompatible types'.
I never know the number of packets I may receive in one physical packet so I wanted to increase the length of the array if the number increases.
How do I solve my errors?