Witam
Chciałbym Was poprosić o sprawdzenie czy dobrze przetłumaczyłem kod w c# na Delphi.
Kod ma za zadanie z tablicy bajtów wyciągnąć kilku bajtową wartość liczbową.
kod w c#:
unsafe
{
fixed (byte* Addr = &ReceiveBuffer[IndexRB])
{
if ((Type & 0x80) == 0x80)
{
if (Size == 0x01) return *(char*)Addr;
if (Size == 0x02) return *(short*)Addr;
if (Size == 0x04) return *(int*)Addr;
}
if (Size == 0x01) return *(byte*)Addr;
if (Size == 0x02) return *(ushort*)Addr;
if (Size == 0x04) return *(uint*)Addr;
}
}
kod w Delphi:
type
PInteger = ^Integer;
type
Pcardinal = ^Cardinal;
type
Pword = ^word;
type
Psmallint = ^SmallInt;
type
Pshortint = ^ShortInt;
Addr := @ReceiveBuffer[IndexRB];
if Typ >= $80 then
begin
if Size = $01 then begin result := Pshortint(Addr); exit; end;
if Size = $02 then begin result := Psmallint(Addr); exit; end;
if Size = $04 then begin result := Pinteger(Addr); exit; end;
end;
if Size = $01 then begin result := Addr^; exit; end;
if Size = $02 then begin result := Pword(Addr); exit; end;
if Size = $04 then begin result := Pcardinal(Addr); exit; end;