Problem Source: http://www.cnblogs.com/del/archive/2010/05/28/1746514.html#1835637
Code:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) edit1: tedit; button1: tbutton; opendialog1: topendialog; Procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.formcreate (Sender: tobject); begin edit1.text: = '10'; // 10 KB edit1.numbersonly: = true; opendialog1.filter: = 'text | *. TXT | *. * | *. * '; end; Procedure tform1.button1click (Sender: tobject); var FS: tfilestream; Ms: tmemorystream; Path: string; size, sizeend, Count, I: integer; C: Char; begin if opendialog1.execute then path: = opendialog1.filename; if not fileexists (PATH) Then exit; FS: = tfilestream. create (path, fmopenread); FS. read (C, 1); If charinset (C, [# $ EF, # $ Fe, # $ ff]) then begin showmessage ('only applies to text files in ANSI format '); FS. free; exit; end; tbutton (sender ). enabled: = false; Size: = strtointdef (edit1.text, 10) * 1024; count: = FS. size DIV size; sizeend: = FS. size mod size; If sizeend> 0 then Inc (count); MS: = tmemorystream. create; FS. position: = 0; for I: = 0 to count-1 do begin text: = format ('% d/% d', [I + 1, Count]); application. processmessages; if (I = count-1) Then size: = sizeend; Ms. size: = size; FS. read (Ms. memory ^, size); ms.savetofile(format('s_s_%.3d.txt ', [changefileext (path, ''), I + 1]); FS. position: = size * (I + 1); end; FS. free; Ms. free; tbutton (sender ). enabled: = true; text: = 'complete'; end.
Form:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 122 clientwidth = 231 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 edit1: tedit left = 80 top = 24 width = 75 Height = 21 taborder = 0 text = 'edit1' end object button1: tbutton left = 80 top = 62 width = 75 Height = 25 caption = 'button1' taborder = 1 onclick = button1click end object opendialog1: topendialog left = 24 Top = 40 endend