Example of a string to an array-replying to the "red" issue is of little reference to other friends

Source: Internet
Author: User
Problem Source: http://www.cnblogs.com/del/archive/2008/11/04/1209070.html#1360634
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) memo1: tmemo; button1: tbutton; procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} const STR = '30, 80: 30: bd6b09: 10: 1850: Suzhou: 88 & 50,140: 120: 976d00: 8: 150: Suzhou: 88 & '+' 130, 80: 150: c50023: 5: 850: Suzhou: 88 & 100,140: 280: cae5e8: 15: 450: Suzhou: 88 & '+ '180,190: 190: 780062: 7: 3850: Suzhou: 88 & 130,180: 30: bd6b09: 10: 1850: Wuxi: 88 & '+ '150, 40: 120: 976d00: 8: 150: Wuxi: 88 & 90,180: 150: c50023: 5: 850: Wuxi: 88 & '+ '10, 80: 280: cae5e8: 15: 450: Wuxi: 88 & 150,120: 190: 780062: 7: 3850: Wuxi: 88 '; Type tmyrec = record longpolling: single; {longitude} latitude: single; {latitude} angle: single; {angle} color: tcolor; {color} size: Cardinal; {size} value: Cardinal; {value} Name: string; {name} number: integer; {number} end; tmyarr = array of tmyrec; {conversion process} procedure mystr2arr (const STR: string; var arr: tmyarr); var list1, list2, list3: tstringlist; I: integer; begin setlength (ARR, 0); list1: = tstringlist. create; list2: = tstringlist. create; list3: = tstringlist. create; list1.delimiter: = '&'; list1.delimitedtext: = STR; list2.delimiter: = ':'; for I: = 0 to list1.count-1 do begin list2.delimitedtext: = list1 [I]; if list2.count 7 then exit; {the original data is invalid} list3.commatext: = list2 [0]; setlength (ARR, length (ARR) + 1); with arr [high (ARR)] do begin longpolling: = strtofloatdef (list3 [0], 0); latitude: = strtofloatdef (list3 [1], 0); angle: = strtofloatdef (list2 [1], 0); color: = tcolor (strtointdef (list2 [2], 0); Size: = strtointdef (list2 [3], 0); value: = strtointdef (list2 [4], 0); Name: = list2 [5]; number: = strtointdef (list2 [6], 0); end; list1.free; list2.free; list3.free; end; {test} procedure tform1.button1click (Sender: tobject); var mydataarr: tmyarr; I: integer; begin mystr2arr (STR, mydataarr); for I: = 0 to length (mydataarr)-1 do with mydataarr [I] Do memo1.lines. add (format ('% F, % F: % F, % d, % s, % d', [longpolling, latitude, angle, color, size, value, name, number]); memo1.lines. add (''); end; Procedure tform1.formcreate (Sender: tobject); begin memo1.clear; memo1.align: = altop; memo1.scrollbars: = ssboth; end.
 
   
 

Form file:

 
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 227 clientwidth = 304 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 button1: tbutton left = 120 top = 191 width = 75 Height = 25 caption = 'button1' taborder = 0 onclick = button1click end object memo1: tmemo left = 24 Top = 0 width = 185 Height = 185 lines. strings = ('memo1') taborder = 1 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.