Functions that use the tbytesstream class to read files with hexadecimal characters

Source: Internet
Author: User
In this example:


Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) memo1: tmemo; memo2: tmemo; button1: tbutton; Procedure button1click (Sender: tobject); Procedure formcreate (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} {function for reading hexadecimal characters} function readfiletohex (filename: string): string; var BS: tbytesstream; I: integer; begin result: = ''; if not fileexists (filename) Then exit; BS: = tbytesstream. create; BS. loadfromfile (filename); for I: = 0 to BS. size-1 do result: = Result + format ('%. 2x ', [BS. bytes [I]); BS. free; end; {test} procedure tform1.button1click (Sender: tobject); const filepath = 'C: \ temp \ text.txt '; begin memo1.lines. savetofile (filepath); memo2.text: = readfiletohex (filepath); end; Procedure tform1.formcreate (Sender: tobject); begin button1.caption: = 'save and read the hexadecimal format (note that the 0d 0a read is a line break) '; end.

  

Form file:

 
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 149 clientwidth = 339 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false oncreate = formcreate pixelsperinch = 96 textheight = 13 object memo1: tmemo left = 0 Top = 0 width = 160 Height = 124 align = alleft lines. strings = ('memo1') scrollbars = ssvertical taborder = 0 end object memo2: tmemo left = 179 Top = 0 width = 160 Height = 124 align = alright lines. strings = ('memo2') scrollbars = ssvertical taborder = 1 end object button1: tbutton left = 0 Top = 124 width = 339 Height = 25 align = Albottom caption = 'button1' taborder = 2 onclick = button1click endend

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.