procedure TForm1.Button1Click(Sender: TObject);
var
i,i2:Integer ;
data:array of byte;
s:string;
hfile:THandle;
byteswrite:dWord;
begin
s:='486F6D65B9E6B8F1A3BA';
i2:=Length(s) div 2;
SetLength(data,i2);
for i:=0 to Length(data)-1 do
begin
data[i]:=StrToInt('$'+copy(s,i*2+1,2));
Edit1.Text :=Edit1.Text + inttohex(data[i],2);
end;
hFile := CreateFile('d:\xxx.bmp',GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ,nil,CREATE_ALWAYS,0,0);
if hFile = INVALID_HANDLE_VALUE then Exit;
WriteFile(hFile,data,Length(data)+1,BytesWrite,nil);
CloseHandle(hFile);
end;
-----------------------
为什么我这段代码写进去的内容跟我预期不一样
486F6D65B9E6B8F1A3BA
变成
6426D5006CF71200D6F9但是如果将数组写成: data:array[0..9] of byte = ($48,$6F ...)
这样可以写入的,而且是正确的
var
i,i2:Integer ;
data:array of byte;
s:string;
hfile:THandle;
byteswrite:dWord;
begin
s:='486F6D65B9E6B8F1A3BA';
i2:=Length(s) div 2;
SetLength(data,i2);
for i:=0 to Length(data)-1 do
begin
data[i]:=StrToInt('$'+copy(s,i*2+1,2));
Edit1.Text :=Edit1.Text + inttohex(data[i],2);
end;
hFile := CreateFile('d:\xxx.bmp',GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ,nil,CREATE_ALWAYS,0,0);
if hFile = INVALID_HANDLE_VALUE then Exit;
WriteFile(hFile,data,Length(data)+1,BytesWrite,nil);
CloseHandle(hFile);
end;
-----------------------
为什么我这段代码写进去的内容跟我预期不一样
486F6D65B9E6B8F1A3BA
变成
6426D5006CF71200D6F9但是如果将数组写成: data:array[0..9] of byte = ($48,$6F ...)
这样可以写入的,而且是正确的
解决方案 »
- indy 如何屏蔽超时链接的红框
- WPS office 2007非常不错,建议大家使用。与Office 2003完全兼容。个人免费。
- IT技术交流 QQ群10206167 欢迎加入 可以讨论各类的IT技术问题。
- 谁有没有 用TWebbrower 捕捉DHTML控件的事件的例子???
- 在C/S结构中,查询数据的问题?
- 奇怪的问题---急切盼望大虾指点
- 请教:怎么调用可执行文件?
- webservice(dll格式)部署到2003server上的问题
- 数据类型的转换?
- 我插入的记录为什么退出程序就没有了呢?我用的是query和UpdateSQL?????
- TDataSource 里的dataset 找不到 TADOQuery..?
- 如何在Onshow中添加过程
var
i,i2:Integer ;
data:array of byte;
s:string;
hfile:THandle;
byteswrite:dWord;
FS : TFileStream;
begin
s:='486F6D65B9E6B8F1A3BA';
i2:=Length(s) div 2;
SetLength(data,i2);
for i:=0 to Length(data)-1 do
begin
data[i]:=StrToInt('$'+copy(s,i*2+1,2));
Edit1.Text :=Edit1.Text + inttohex(data[i],2);
end;
fs:=TFileStream.Create('d:\xxx.bmp',fmCreate or fmShareDenyRead);
fs.Write(pchar(@data[0])^,Length(data));
freeAndNil(fs);
end;