Цитата:
Имейте ввиду, что когда у вас дойдет дело до обработки Золота, которое занимает 4 байта вам надо будет читать в переменную типа DWord а не Byte, т.е. добавьте в описание переменную D: DWord и чтение золота будет так:
|
Вопрос первый: ошибка.
Incompatible types: byte and cardinal
Листинг:
Код:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | var
Form1: TForm1;
f : file of byte ;
b : byte ;
zol : dword;
implementation
{$R *.dfm}
procedure TForm1 . FormActivate(Sender: TObject);
begin
AssignFile(f, 'savegame00.sav' );
FileMode := fmOpenReadWrite;
Reset(f);
Seek(f, 186747 );
Read(f, b);
Seek(f, 186748 );
??? Read(f, zol);
CloseFile(f);
Edit1 . Text := IntToStr(b);
Edit2 . Text := IntToStr(zol);
end ;
|
Вопрос второй (сделал по-своему): можно ли упростить код? И вопрос вдогонку: что делать, если побайтовый offset на 4 делиться не будет? (186748/4 = 46687, но так может быть не всегда)
Листинг:
Код:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | var
Form1: TForm1;
f : file of byte ;
b : byte ;
ff : file of cardinal ;
zol : dword;
implementation
{$R *.dfm}
procedure TForm1 . FormActivate(Sender: TObject);
begin
AssignFile(f, 'savegame00.sav' );
FileMode := fmOpenReadWrite;
Reset(f);
Seek(f, 186747 );
Read(f, b);
AssignFile(f, 'savegame00.sav' );
FileMode := fmOpenReadWrite;
Reset(ff);
Seek(ff, 46687 );
Read(ff, zol);
Edit1 . Text := IntToStr(b);
Edit2 . Text := IntToStr(zol);
end ;
|