Use of Delphi streaming (10): compression and decompression progress-Reply to "ilst"

Source: Internet
Author: User
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

  

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.