P
panyongze
Unregistered / Unconfirmed
GUEST, unregistred user!
我自定义了一个类,其中有一个函数执行时间比较长。
如何将执行进度反馈给调用者?
执行期间如何刷新页面?
调用单元
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MyUnit, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
aa:TMyClass;
begin
aa:= TMyClass.Create;
aa.MaxValue:=99999;
aa.MinValue:=-999999;
aa.SaveToMyFile('aaa.txt');
aa.Free;
end;
end.
自定义单元
unit MyUnit;
interface
type
TMyClass = class(TObject)
private
FMaxValue:Integer;
FMinValue:Integer;
FPlan:Integer;
public
procedure SaveToMyFile(OutFileName: String);
property MaxValue: Integer read FMaxValue write FMaxValue default MaxInt;
property MinValue: Integer read FMinValue write FMinValue default -MaxInt;
property Plan: Integer read FPlan;
end;
implementation
uses SysUtils;
procedure TMyClass.SaveToMyFile(OutFileName: String);
var
OutFile: TextFile;
I,J: Integer;
S: String;
begin
AssignFile(OutFile,OutFileName);
ReWrite(OutFile);
J := FMaxValue-FMinValue;
for I := FMinValue to FMaxValue do
begin
S := IntToStr(I);
Writeln(OutFile,S);
FPlan := I*100 Div J
//执行进度
end;
CloseFile(OutFile);
end;
end.
如何将执行进度反馈给调用者?
执行期间如何刷新页面?
调用单元
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MyUnit, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
aa:TMyClass;
begin
aa:= TMyClass.Create;
aa.MaxValue:=99999;
aa.MinValue:=-999999;
aa.SaveToMyFile('aaa.txt');
aa.Free;
end;
end.
自定义单元
unit MyUnit;
interface
type
TMyClass = class(TObject)
private
FMaxValue:Integer;
FMinValue:Integer;
FPlan:Integer;
public
procedure SaveToMyFile(OutFileName: String);
property MaxValue: Integer read FMaxValue write FMaxValue default MaxInt;
property MinValue: Integer read FMinValue write FMinValue default -MaxInt;
property Plan: Integer read FPlan;
end;
implementation
uses SysUtils;
procedure TMyClass.SaveToMyFile(OutFileName: String);
var
OutFile: TextFile;
I,J: Integer;
S: String;
begin
AssignFile(OutFile,OutFileName);
ReWrite(OutFile);
J := FMaxValue-FMinValue;
for I := FMinValue to FMaxValue do
begin
S := IntToStr(I);
Writeln(OutFile,S);
FPlan := I*100 Div J
//执行进度
end;
CloseFile(OutFile);
end;
end.