W
wintle
Unregistered / Unconfirmed
GUEST, unregistred user!
由于LoadFromFile()时有些慢,所以每次预览或打印,在第一次时总会较慢,载入后速度就很快了。所以我想是否可能在程序开始运行后,用一个背后的线程,先把报表给载入进来。这样要用的时候,就很快了。。
但我没有做成功,代码如下,请帮我看一下:
LoadPactInMultiThread.pas :
unit LoadPactInMultiThread;
interface
uses
Forms,Classes,SysUtils,RM_Common,RM_Class,RM_GridReport;
type
TLoadPact = class(TThread)
private
public
constructor Create;
procedure Load(rm:TRMGridReport;doc:TRMReport;path:string;owner:TForm);
end;
implementation
constructor TLoadPact.Create;
begin
FreeOnTerminate := true;
inherited Create(False);
end;
procedure TLoadPact.Load(rm:TRMGridReport;doc:TRMReport;path:string;owner:TForm);
begin
rm := TRMGridReport.Create(owner);
do
c := TRMReport.Create(owner);
rm.LoadFromFile(path+'Report.rls');
do
c.LoadFromFile(path+'EditorDoc.rmf');
// rm := rmreport.
end;
end.
=======================================================
在主窗口的OnShow()事件中启动这个线程:
procedure TMain.FormShow(Sender: TObject);
var
loadpact : TLoadPact;
begin
if not self.PrintPageLoaded then
begin
loadpact := TLoadPact.Create;
loadpact.Priority := tpLower;
loadpact.Load(self.rmReport,self.rmDoc,ExtractFilePath(ParamStr(0)),self);
loadpact.OnTerminate := PactLoadWithMultiOk;
end;
end;
========================================================
我想这是有意义的哈,请大家帮我看看,谢谢。
提示是 EAbstractError,跟踪进去后,是在 LoadFromFile函数的 LoadFromStream()处
如下:
if FileExists(aFileName) then
begin
liStream := TFileStream.Create(aFileName, fmOpenRead);
try
LoadFromStream(liStream);
《==这句报错。
...
谢谢。
但我没有做成功,代码如下,请帮我看一下:
LoadPactInMultiThread.pas :
unit LoadPactInMultiThread;
interface
uses
Forms,Classes,SysUtils,RM_Common,RM_Class,RM_GridReport;
type
TLoadPact = class(TThread)
private
public
constructor Create;
procedure Load(rm:TRMGridReport;doc:TRMReport;path:string;owner:TForm);
end;
implementation
constructor TLoadPact.Create;
begin
FreeOnTerminate := true;
inherited Create(False);
end;
procedure TLoadPact.Load(rm:TRMGridReport;doc:TRMReport;path:string;owner:TForm);
begin
rm := TRMGridReport.Create(owner);
do
c := TRMReport.Create(owner);
rm.LoadFromFile(path+'Report.rls');
do
c.LoadFromFile(path+'EditorDoc.rmf');
// rm := rmreport.
end;
end.
=======================================================
在主窗口的OnShow()事件中启动这个线程:
procedure TMain.FormShow(Sender: TObject);
var
loadpact : TLoadPact;
begin
if not self.PrintPageLoaded then
begin
loadpact := TLoadPact.Create;
loadpact.Priority := tpLower;
loadpact.Load(self.rmReport,self.rmDoc,ExtractFilePath(ParamStr(0)),self);
loadpact.OnTerminate := PactLoadWithMultiOk;
end;
end;
========================================================
我想这是有意义的哈,请大家帮我看看,谢谢。
提示是 EAbstractError,跟踪进去后,是在 LoadFromFile函数的 LoadFromStream()处
如下:
if FileExists(aFileName) then
begin
liStream := TFileStream.Create(aFileName, fmOpenRead);
try
LoadFromStream(liStream);
《==这句报错。
...
谢谢。