String Conversion to wide characters in the specified format-reply to the "Chef" question

Source: Internet
Author: User
Problem Source: http://www.cnblogs.com/del/archive/2008/12/13/1353193.html#1400641

In this example:


Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) memo1: tmemo; button1: tbutton; edit1: tedit; Procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); Procedure memo1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.button1click (Sender: tobject); var STR: string; pcw: pwidechar; CW: widechar; I: integer; begin memo1.clear; STR: = edit1.text; pcw: = pwidechar (STR); for I: = 0 to strlen (pcw)-1 do begin cw: = (pcw + I) ^; memo1.lines. add (format ('$ %. 4x ', [ord (CW)]); // memo1.lines. add (format ('$ %. 4x ', [ord (STR [I + 1]); {You can also use this sentence to replace the above two rows} end; Procedure tform1.formcreate (Sender: tobject ); begin memo1.clear; memo1.align: = alleft; cursor: = ssvertical; end; Procedure tform1.memo1click (Sender: tobject); var STR: string; begin STR: = memo1.lines [memo1.caretpos. y]; text: = widechar (strtointdef (STR, 0); end.
 
   
 

Form file:

 
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 190 clientwidth = 260 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 = 8 Top = 8 width = 89 Height = 185 lines. strings = ('memo1') taborder = 0 onclick = memo1click end object button1: tbutton left = 136 Top = 120 width = 75 Height = 25 caption = 'button1' taborder = 1 onclick = button1click end object edit1: tedit left = 95 Top = 16 width = 157 Height = 21 taborder = 2 text = 'edit1' 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.