Or
type
TByteOrWord = record
case Integer of
0: (Lo, Hi: Byte);
1: (AsWord: Word);
end;
var
W: TByteOrWord;
begin
W.Hi := 1;
W.Lo := 2;
ShowMessage(IntToStr(W.AsWord));
end;
Cheers,
Carl
-----Original Message-----
From: Aaron Scott-Boddendijk [mailto:[EMAIL PROTECTED]]
Sent: Friday, 4 August 2000 10:36 AM
To: Multiple recipients of list delphi
Subject: Re: [DUG]: Coverting Binary Streams
> for example, if I have a TByteArray and I want to get bytes 4 and 5 and
> convert them to a word, how do I go about doing that?
>
> In Jade the code looks like:
>
> myArray[4 : 5].Integer;
>
> Do I need to defined record types of the various sizes I need, chuck the
> bytes into there and convert?
>
var
W :Word;
MyArray :array[0..1] of Byte;
begin
MyArray[0] := 1;
MyArray[1] := 2;
// MyArray[1] is MSB
W := (PWord(@MyArray[0]))^;
showmessage(inttostr(W));
// MyArray[0] is MSB
W := (MyArray[0] SHL 8) + MyArray[1];
showmessage(inttostr(W));
end;
--
Aaron Scott-Boddendijk
Jump Productions
(07) 838-3371 Voice
(07) 838-3372 Fax
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz