Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#11

Re: Cardinal in Bytes speichern

  Alt 27. Okt 2008, 22:28
Zitat von xZise:
Wie stellst du dir das vor?
Naja so:


Delphi-Quellcode:
type
  TFoo = packed record
    case Integer of
      0: (arr: array[0..5] of Byte);
      1: (
           dummy1: Word;
           Wert: Cardinal;
         );
  end;

var foo: TFoo;
    i: Integer;
begin
  // foo füllen
  for i:= 0 to 5 do
    foo.arr[i] := random(256); // ka.. deine daten halt
  // Du willst jetzt nur den Errorcode?
  // ==>
  // Der steht in foot.Wert:
  Send(foo.Wert);
end;
Oder eben umgekehrt. In den Cardinal schreiben und die Bytes auslesen. Die 6 Bytes und der 1. Word + der Cardinal belegen den gleichen Speicher:

Code:
-----------------------------------------------------
| Byte1 | Byte2 | Byte3 | Byte4 | | Byte5 | | Byte6 |
------------------------------------------------------
|    dummy1     |       W     e     r     t     |
------------------------------------------------------
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat