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 ...)
这样可以写入的,而且是正确的
解决方案 »
- 高手请进!报价单生成问题
- delphi7写的一个串口通讯程序 在自己的机器上可以运行 用Inno Setup打包后到其他机器上不能运行
- ★新手请教一个函数调用的问题??
- 请教 delphi 怎么连接 mysql ??
- 我有一个interbase数据库,我想用delphi实现将一个表导出为fox或access数据表,如何实现?
- 比较麻烦的数据输入问题?高手请进。
- 我在WIN2000中编的程序,在WION98中全走了样,能解决吗?
- Clx应用程序中的TPrinter对象的问题。
- sql的问题,急急!!
- 请教一API问题......
- 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;