![]() |
Re: Cardinal in Bytes speichern
Zitat:
Delphi-Quellcode:
Oder eben umgekehrt. In den Cardinal schreiben und die Bytes auslesen. Die 6 Bytes und der 1. Word + der Cardinal belegen den gleichen Speicher:
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;
Code:
-----------------------------------------------------
| Byte1 | Byte2 | Byte3 | Byte4 | | Byte5 | | Byte6 | ------------------------------------------------------ | dummy1 | W e r t | ------------------------------------------------------ |
Re: Cardinal in Bytes speichern
Moin moin,
eine weitere Möglichkeit wäre noch der Weg über Pointer:
Delphi-Quellcode:
//...
var Arr : Array[0..5] of Byte; P : PCardinal; Wert : Cardinal; begin Wert := 4294967295; //Cardinal in Array scheiben P := @Arr[2]; P^:= Wert; // und wieder auslesen // Little Endian //WertNeu := (Arr[5] shl 24) or (Arr[4] shl 16) or (Arr[3] shl 8) or Arr[2]; xxx := PCardinal(@Arr[2])^; //... //... // bzw gleich so PCardinal(@Arr[2])^ := 4294967295; // und auslesen halt wieder xxx := PCardinal(@Arr[2])^; |
Re: Cardinal in Bytes speichern
Zitat:
MfG xZise |
Re: Cardinal in Bytes speichern
Zitat:
|
Re: Cardinal in Bytes speichern
Moin moin,
wie gesagt, dass war nur eine weitere Möglichkeit. Ich persönlich würde die Variante von ![]() auch bevorzugen. |
Re: Cardinal in Bytes speichern
Habs grad mal getestet, scheint noch zu funktionieren, entschuldigt die unnötige Verwirrung :stupid:
Delphi-Quellcode:
TA: 8 Bytes
TA = record
AByte: Byte; BInt: Integer; end; TB = packed record AByte: Byte; BInt: Integer; end; TB: 5 Bytes |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:41 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz