Hi,
I have a TRecord with e.g. 100 members, all of them are bytes. I receive data from outside as an array of bytes.
Is there a way to copy the array values to the TRecord members in a loop?
Pseudocode of what I am doing at the moment:
type
MyInternalStorage = record
Param1: byte;
Param2: byte
...
end;
MyReceivedData: array[0..99] of byte;
function CopyArrayToRecord(aPar: MyReceivedData): boolean;
var
i: integer;
begin
Result := True;
try
for i := low(aPar) to high(aPar) do
FillByte(MyInternalStorage , SizeOf(byte), aPar[i]);
except
on e: Exception do Result := False;
end;
end;
Is this OK or am I doing a memory corruption of MyInternalStorage record this way?
Second problem would be, would this cast work?
MyInternalStorage(MyReceivedData).Param1
Compiler does not complain, but I am not sure if this is OK at all.