In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) memo1: tmemo; memo2: response; Panel1: tpanel; button1: tbutton; button2: tbutton; button3: tbutton; button4: tbutton; button5: tbutton; button6: tbutton; Procedure response (Sender: tobject ); procedure extract (Sender: tobject); Procedure button2click (Sender: tobject); Procedure extract (Sender: tobject ); procedure button6click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} {function from string to hexadecimal} function strtohex (STR: string; aencoding: tencoding): string; var SS: tstringstream; I: integer; begin result: = ''; SS: = tstringstream. create (STR, aencoding); for I: = 0 to SS. size-1 do result: = Result + format ('%. 2x ', [ss. bytes [I]); SS. free; end; Procedure tform1.button1click (Sender: tobject); begin memo2.text: = strtohex (memo1.text, tencoding. ASCII); end; Procedure tform1.button2click (Sender: tobject); begin memo2.text: = strtohex (memo1.text, tencoding. unicode); end; Procedure tform1.button3click (Sender: tobject); begin memo2.text: = strtohex (memo1.text, tencoding. utf7); end; Procedure tform1.button4click (Sender: tobject); begin memo2.text: = strtohex (memo1.text, tencoding. utf8); end; Procedure tform1.button5click (Sender: tobject); begin memo2.text: = strtohex (memo1.text, tencoding. default); end; Procedure tform1.button6click (Sender: tobject); begin memo2.text: = strtohex (memo1.text, tencoding. bigendianunicode); end; Procedure encode (Sender: tobject); begin button1.caption: = 'to ASCII '; button2.caption: = 'to Unicode'; button3.caption: = 'to utf7 '; button4.caption: = 'to utf8'; button5.caption: = 'to default'; button6.caption: = 'to bigendianunicode '; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 156 clientwidth = 353 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 = 145 Height = 88 align = alleft lines. strings = ('memo1') scrollbars = ssvertical taborder = 0 end object memo2: tmemo left = 157 Top = 0 width = 196 Height = 88 align = alright lines. strings = ('memo2') scrollbars = ssvertical taborder = 1 end object Panel1: tpanel left = 0 Top = 88 width = 353 Height = 68 align = Albottom taborder = 2 object button1: tbutton left = 16 Top = 6 width = 73 Height = 25 caption = 'button1' taborder = 0 onclick = button1click end object button2: tbutton left = 95 Top = 6 width = 74 Height = 25 caption = 'button2' taborder = 1 onclick = button2click end object button3: tbutton left = 175 Top = 6 width = 82 Height = 25 caption = 'button3' taborder = 2 onclick = button3click end object button4: tbutton left = 263 Top = 6 width = 74 Height = 25 caption = 'button4' taborder = 3 onclick = button4click end object button5: tbutton left = 16 Top = 37 width = 96 Height = 25 caption = 'button5' taborder = 4 onclick = button5click end object button6: tbutton left = 130 Top = 37 width = 207 Height = 25 caption = 'button6' taborder = 5 onclick = button6click end endend