Delphi字节转换字节数组

procedure TForm1.btn2Click(Sender: TObject);
var
f1:File of byte;
aa:byte;
begin
AssignFile(f1,'2.exe');
try
reset(f1);
seek(f1,300938); //定位到第300938个字节处,位置你可以自己定
read(f1,aa); //读出一个字节,赋值给aa
aa:=$74; //修改aa的值
seek(f1,300938); //重新定位,因为读数据后,指针指向了下一个字节
write(f1,aa); //将修改后的值写回原位
finally
closeFile(f1);
end; //end of try
end;

procedure TForm1.btn3Click(Sender: TObject);
var
f1:File of byte;
bb:byte;
begin
AssignFile(f1,'2.exe');
try
reset(f1);
seek(f1,300939); //定位到第300939个字节处,位置你可以自己定
read(f1,bb); //读出一个字节,赋值给aa
bb:=$31; //修改aa的值
seek(f1,300939); //重新定位,因为读数据后,指针指向了下一个字节
write(f1,bb); //将修改后的值写回原位
finally
closeFile(f1);
end; //end of try
end;

procedure TForm1.btn4Click(Sender: TObject);
var
f1:File of byte;
cc:byte;
begin
AssignFile(f1,'2.exe');
try
reset(f1);
seek(f1,300940); //定位到第300940个字节处,位置你可以自己定
read(f1,cc); //读出一个字节,赋值给aa
cc:=$5c; //修改aa的值
seek(f1,300940); //重新定位,因为读数据后,指针指向了下一个字节
write(f1,cc); //将修改后的值写回原位
finally
closeFile(f1);
end; //end of try
end;

end.

谁能帮我把aa,bb,cc三个字节转换成数组。
就是把这三句代码合成一句代码!

你的代码只读出那个字节又没做别的处理,因此不用Read了。因为你那三个字节都是连续的,因此可以用一个byte数组,如下:
var
F :File;
Buf: array[0..2] of byte;
begin
AssignFile(F, '2.exe');
try
Reset(F,1);
Buf[0]:=$74;
Buf[1]:=$31;
Buf[2]:=$5c;
seek(F,300938);//从300938开始写3个字节
BlockWrite(F, Buf, SizeOf(Buf));
finally
CloseFile(F);
end;
end;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-19
procedure TForm1.btn4Click(Sender: TObject);
var
f1:File of byte;
cc:byte;
alist:array of Longint; //新加
blist:array of Longint; //新加
I:integer; //新加
begin
SetLength(aList, 3) ; //新加
SetLength(bList, 3) ; //新加
aList[0]:=300938;
aList[1]:=300939;
aList[2]:=300940; //新加
bList[0]$74;
bList[1]:=$31;
bList[2]:=$5c;
AssignFile(f1,'2.exe');
try
for I := 0 to 3 do //新加
begin

reset(f1);
seek(f1,aList[I]); //修改 //定位到第300940个字节处,位置你可以自己定
read(f1,cc); //读出一个字节,赋值给cc
// cc:=$5c; //修改aa的值
cc:=bList[I]; //新修改
seek(f1,aList[I]); //重新定位,因为读数据后,指针指向了下一个字节
write(f1,cc); //将修改后的值写回原位
end;
finally
closeFile(f1);
end; //end of try
end;

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网