Method of executing the meat folder

Source: Internet
Author: User

In many cases, we encounter the following situation:

In the front and back sections of many methods (there may be only one sentenceCode. For example, in a process that takes some time, we often display a progress bar while processing it. This gives customers and ourselves a little confidence. However, if there is a lot of such processing, we will find such code

Procedure route M1;

Begin

Showaprogress ('connecting... ');

.....

Closeprogress;

End;

Procedure sans Mn

Begin

Showaprogress ('processing ××, please wait... ');

.....

Closeprogress;

End;

Obviously, our code is repeated. There are many solutions to this problem. I don't know how others solve the problem. Here is my solution:

Type
Tproc = procedure of object;
 

Procedure runwithprogress (P: tproc); // I call it the cookie method. I wonder if you have any comments.

Implementation

Procedure tform1.aloop; // a specific processing.
VaR
Iloop: integer;
Begin
Chk1.checked: = true;
While chk1.checked do
Begin
Application. processmessages;
INC (iloop );
End;
End;

Procedure tform1.runwithprogress (P: tproc); // implement the pie.
Begin
Showgaugewithavi ('it is running ....');
P;
Closegauge;
End;

Procedure tform1.button1click (Sender: tobject); // you only need to call the cookie each time.
VaR
P: tproc;
Begin
P: = aloop;
Runwithprogress (P );
End;

End.

 

I wonder if I have different opinions...

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.