Autor Beitrag
Biarchiv
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 688



BeitragVerfasst: Mi 09.04.03 20:52 
Hallo,

Habe folgendes Problem.

Wenn ich nun 4 Bytes auf einen Integer lege und dort etwas addieren.

Dann trenne ich den Integer wieder in die 4 Bytes.
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
test := int1 + $200;

int1 := LOWORD(test);
int2 := HIWORD(test);
Byte1 := LOBYTE(int1);
Byte2 := HIBYTE(int1);
Byte3 := LOBYTE(int2);
Byt41 := HIBYTE(int2);

File1.write(Byte1, 1);
File1.write(Byte2, 1);
File1.write(Byte3, 1);
File1.write(Byte4, 1);


Nur leider werden da nur 00000000h geschrieben
Wo liegt da der Fehler?
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 09.04.03 21:15 
Ich vermute mal du hast trouble mit den typen!?

Versuch mal dies:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var int1, int2, test: DWord; // könnte an integer liegen -> DWord ist unassigned -> IMHO  deshalb hierfür besser
...
test := int1 + $200;

byte1 := test and $FF;
byte2 := (test shr 8) and $FF;
byte3 := (test shr 16) and $FF;
byte4 := (test shr 24) and $FF;


PS: das konzept von integer und word ist natürlich grundlegend verschieden, weshalb die funktionen LoWord etc. nicht gehn. Hiermit geht es vielleicht auch mit integer typen :wink:

_________________
mfg.
mâximôv
Biarchiv Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 688



BeitragVerfasst: Do 10.04.03 20:52 
Hallo,

Ahh, Danke. Ja das mit write scheint zu gehen.
Nur habe ich mit read noch ein problem.

Ich habe hier den Code. Er ließt die Werte falsch ein obwohl es die richtige Position ist:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
var
   dos1, dos2, dos3, dos4, sn1, sn2, soi1, soi2, soi3, soi4 : byte;
 soierg, Byte1, Byte2, Byte3, Byte4 : DWord;

  File1.seek(pepos, soFromBeginning); // PE -
  File1.seek(+82, soFromCurrent); // SizeOfHeaders
  File1.read(soi4,1);
  File1.read(soi3,1);
  File1.read(soi2,1);
  File1.read(soi1,1);
  //  soierg := MakeLONG(MAKEWORD(soi1, soi2), MAKEWORD(soi3, soi4));
  soierg := MakeLONG(soi1, soi2) AND MAKELONG(soi3, soi4);
  showmessage(inttostr(soierg));
  soierg := soierg + $200; //add sizeofheader entry
  Byte1 := soierg and $FF;
  Byte2 := (soierg shr 8 ) and $FF;
  Byte3 := (soierg shr 16) and $FF;
  Byte4 := (soierg shr 24) and $FF;
  File1.seek(-4, soFromCurrent);
  File1.write(Byte1, 1);
  File1.write(Byte2, 1);
  File1.write(Byte3, 1);
  File1.write(Byte4, 1);   // Write new SizeOFHeaders
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Fr 11.04.03 10:19 
Zitat:
soierg := MakeLONG(soi1, soi2) AND MAKELONG(soi3, soi4);
Damit kombinierst du zwei longs mit dem logischen AND operator, du müsstest vorher allerdings eins der beiden an die richtige bit-position shiften:xyz := MAKEWORD(soi1, soi2)and (MAKEWORD(soi3, soi4) shl 16); Ich würd hier word nehmen...solang die ziel-variable 32-bit hat passt das. Ich glaub long ist übertrieben :wink:

hoffe et funzt?

_________________
mfg.
mâximôv