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...