Code: Alles auswählen
{$modeswitch typehelpers on}
{$modeswitch arrayoperators on}
//{$modeswitch multihelpers}
uses
SysUtils;
type
TBytes = array of byte;
TWords = array of word;
var
bytes: TBytes = nil;
words: TWords = nil;
i: integer;
begin
// words := [1, 2, 3, 4, 5, 6, 7, 8];
WriteLn(Length(words));
TBytes(words) += [$22];
TBytes(words) += [$33];
TBytes(words) += [$44];
TBytes(words) += [$55];
WriteLn(Length(words)); // -> 4
WriteLn(Length(TBytes(words))); // -4
WriteLn();
for i := 0 to Length(words) - 1 do begin
WriteLn(words[i], ' ', words[i].ToHexString);
end;
Code: Alles auswählen
0
4
4
13090 3322
21828 5544
30062 756E
120 0078
So wie es scheint addiert der Compiler einfach die Array-Länge, ohne das er prüft ob dies zulässig ist.
Bei der Ausgabe findet man die addierten Bytes im Word.
Ist dies so gewollt, oder wurde sowas merkwürdiges gar noch nie probiert ?