Forum > Beginners

Byte Manipulation

(1/5) > >>

flywire:
How do I rewrite this delphi code for lazurus using lo:

buffer[1]:=LoByte(LoWord(TOCfilesCount));
...
buffer[4]:=HiByte(HiWord(TOCfilesCount));

Where buffer is a byte array and TOCfilesCount is a LongInt.

engkin:

--- Code: ---  PLongInt(@buffer[1])^ := TOCfilesCount;

--- End code ---

GetMem:
If you are on windows just add windows to the uses clauses and you're good to go.


--- Code: ---uses windows;
//...
   buffer[1]:=LoByte(LoWord(TOCfilesCount));           
   buffer[4]:=HiByte(HiWord(TOCfilesCount));
//...

--- End code ---

engkin:
The OP wants buffer[2] and buffer[3] as well.

Awkward:
as alternative:

type
  tTempRecord = record
    case boolean of
      true: (a:longint);
      false: (b:array [0..3] of byte);
  end;

and in code:
  buffer[1]:=tTempRecord(TOCfilesCount).b[0];

as example. no?

Navigation

[0] Message Index

[#] Next page

Go to full version