Problem Source: http://www.cnblogs.com/del/archive/2008/08/02/1022539.html#1275599
This example is modified on the basis of this example: http://www.cnblogs.com/del/archive/2008/01/01/1022539.html
In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, comctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; progressbar1: tprogressbar; Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); Procedure csprogress (Sender: tobject ); {compressed onprogress event} procedure dsprogress (Sender: tobject); {decompressed onprogress event} end; var form1: tform1; implementation {$ R *. DFM} uses zlib; {compressed onprogress event} procedure tform1.csprogress (Sender: tobject); begin progressbar1.position: = INTEGER (tcompressionstream (sender ). position Div 1024); application. processmessages; end; {decompressed onprogress event} procedure tform1.dsprogress (Sender: tobject); begin progressbar1.position: = INTEGER (tdecompressionstream (sender ). position Div 1024); application. processmessages; end; {compression} procedure tform1.button1click (Sender: tobject); var Cs: tcompressionstream; FS, Ms: tmemorystream; num: integer; begin FS: = tmemorystream. create; FS. loadfromfile ('C: \ temp \ test.txt '); {I tested it with a 15 m text file} num: = FS. MS: = tmemorystream. create; Ms. write (Num, sizeof (Num); CS: = tcompressionstream. create (CLmax, MS); {Add these two rows in the original code base} progressbar1.max: = INTEGER (FS. size Div 1024); CS. onprogress: = csprogress; FS. savetostream (CS); CS. free; Ms. savetofile ('C: \ temp \ test.zip x'); Ms. free; FS. free; end; {decompress} procedure tform1.button2click (Sender: tobject); var DS: tdecompressionstream; FS, Ms: tmemorystream; num: integer; begin FS: = tmemorystream. create; FS. loadfromfile ('C: \ temp \ test.zip x'); FS. position: = 0; FS. readbuffer (Num, sizeof (Num); MS: = tmemorystream. create; Ms. setsize (Num); DS: = tdecompressionstream. create (FS); {Add these two lines in the original code} progressbar1.max: = INTEGER (Ms. size Div 1024); DS. onprogress: = dsprogress; DS. read (Ms. memory ^, num); Ms. savetofile ('C: \ temp \ test2.txt '); DS. free; Ms. free; FS. free; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 136 clientwidth = 205 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false pixelsperinch = 96 textheight = 13 object button1: tbutton left = 64 Top = 24 width = 75 Height = 25 caption = #21387 #32553 taborder = 0 onclick = button1click end object button2: tbutton left = 64 Top = 55 width = 75 Height = 25 caption = #35299 #21387 #32553 taborder = 1 onclick = button2click end object progressbar1: tprogressbar left = 24 Top = 97 width = 150 Height = 17 taborder = 2 endend