怎样读注册表中的二进制数据,并将结果以二进制形式显示?(100分)

  • 主题发起人 主题发起人 flyhi
  • 开始时间 开始时间
F

flyhi

Unregistered / Unconfirmed
GUEST, unregistred user!
DELPHI的ReadBinaryData的结果会是一个integer :(<br>怎样读注册表中的二进制数据,并将结果以二进制形式显示?
 
看下面的程序段,返回的确实是INTEGER, 但它表示返回的字节数,实际读入的内容<br>在buffer中。想要以二进制形式显示,把它转换一下,或找到能显示二进制的控件。<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var finifile : TRegistry;<br>&nbsp; &nbsp; buffer : array[0..1024] of byte;<br><br>begin<br>&nbsp; finifile := TRegistry.create;<br>&nbsp; FiniFile.OpenKey('/SoftWare/EasySoft/邮件快递/', true);<br>&nbsp; label1.caption := inttostr(FInifile.ReadBinaryData('test',buffer,sizeof(buffer)));<br>&nbsp; bytetostr<br>&nbsp; finifile.Free;<br>end;<br>
 
下面是更完整的程序,不用控件。<br><br>function tohexstr(value:byte): string;<br>var count :integer;<br>&nbsp; &nbsp; howfar,tmp,andresul:word;<br>&nbsp; &nbsp; output :string;<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Howfar:=15;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Output:='';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tmp:=Value;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ One bit at a time }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;For count:=1 To 2 Do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AndResul:=tmp AND Howfar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case AndResul Of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 : OutPut:='0'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 : OutPut:='1'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 : OutPut:='2'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3 : OutPut:='3'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4 : OutPut:='4'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 5 : OutPut:='5'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6 : OutPut:='6'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 7 : OutPut:='7'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 8 : OutPut:='8'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 9 : OutPut:='9'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 : OutPut:='A'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;11 : OutPut:='B'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;12 : OutPut:='C'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;13 : OutPut:='D'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;14 : OutPut:='E'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;15 : OutPut:='F'+Output;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tmp:=tmp DIV 16;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End;<br>&nbsp; result := output;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var finifile : TRegistry;<br>&nbsp; &nbsp; buffer : array[0..1024] of byte;<br>&nbsp; &nbsp; &nbsp;i : integer;<br>begin<br>&nbsp; finifile := TRegistry.create;<br>&nbsp; FiniFile.OpenKey('/SoftWare/EasySoft/邮件快递/', true);<br>&nbsp; label1.caption := inttostr(FInifile.ReadBinaryData('test',buffer,sizeof(buffer))) + ' ';<br>&nbsp; for i := 1 to FInifile.ReadBinaryData('test',buffer,sizeof(buffer)) do<br>&nbsp; &nbsp; &nbsp;label1.caption := label1.caption + ' ' + tohexstr(buffer[i-1]);<br>&nbsp; finifile.Free;<br>end;<br>
 
发现了一个DELPHI的函数,程序简化如下:<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var finifile : TRegistry;<br>&nbsp; &nbsp; buffer : array[0..1024] of byte;<br>&nbsp; &nbsp; &nbsp;i : integer;<br>begin<br>&nbsp; finifile := TRegistry.create;<br>&nbsp; FiniFile.OpenKey('/SoftWare/EasySoft/邮件快递/', true);<br>&nbsp; label1.caption := inttostr(FInifile.ReadBinaryData('test',buffer,sizeof(buffer))) + ' ';<br>&nbsp; for i := 1 to FInifile.ReadBinaryData('test',buffer,sizeof(buffer)) do<br>&nbsp; &nbsp; &nbsp;label1.caption := label1.caption + ' ' + inttohex(dword(buffer[i-1]),2);<br>&nbsp; finifile.Free;<br>end;<br>
 
接受答案了.
 
后退
顶部