: I nead to change any type of variable into an array of byte and back. For now I have it done like so:
:
:
: procedure changetype(var x,y);
: begin
: y:=x
: end;
:
:
: But this only copys the first 4 bytes of the variable x into y.
:
:
: var x,y:array[0..9]of byte;
: i:byte;
: *****
: for i:=0 to 9 do
: x[i]:=i;
:
: changetype(x,y);
:
: for i:=0 to 9 do
: writeln(y[i]);
:
:
: If x is an array of byte [0,1,2,3,4,5,6,7,8,9], after I change the type, y will be [0,1,2,3,0,0,0,0,0,0].
:
: How would I change any type (record, string, longint, word...) into an array of byte? I use Dev-Pascal.
:
Here is a sample code, which might give you the correct results.
type
TByteArray = array of byte;
function ChangeType(const Data): TByteArray;
begin
SetLength(Result, SizeOf(Data)); // Create a long enough array
Move(Data, Result, SizeOf(Data)); // Copy the data into the array
end;
I don't use Dev-Pascal myself, so I'm not sure if the syntax is correct. The most important part of this function is the Move() call, which I think Dev-Pascal should recognize (TP6 through Delphi 5 recognize it).