delphi 多线程fastreport简单实例

type

Tmythread = class(TThread)

protected

  frxrprttmp: TfrxReport;

  procedure Execute; override;

  procedure testPrintThread();

public

  constructor Create(frxrprt: TfrxReport);

end;

var

Form2: TForm2;

implementation

{$R *.dfm}

constructor Tmythread.Create(frxrprt: TfrxReport);

begin

  frxrprttmp := frxrprt;

  inherited Create(False); //false表示线程对象的execute()方法在执行create()方法后立刻自动执行,否则需要在某个地方通过resume后激活该线程

  FreeOnTerminate := False; {这可以让线程执行完毕后随即释放}

end;

procedure Tmythread.Execute();

begin

  Self.Synchronize(testPrintThread);

end;

procedure Tmythread.testPrintThread();

begin

  frxrprttmp.Preview := nil;

  frxrprttmp.PrepareReport;

  frxrprttmp.PrintOptions.ShowDialog := false;

  frxrprttmp.Print;

end;

procedure TForm2.cxbtn_designClick(Sender: TObject);

begin

  frxrprt1.DesignReport();

end;

procedure TForm2.cxbtn_openfr3Click(Sender: TObject);

begin

  if OpenDialog1.Execute then

  begin

    cxTextEdit_1.Text := OpenDialog1.FileName;

  end;

end;

procedure TForm2.cxbtn_previewClick(Sender: TObject);

begin

  frxrprt1.PrepareReport;

  frxrprt1.ShowReport;

end;

procedure TForm2.cxbtn_printClick(Sender: TObject);

var

  i: Integer;

  mythread: Tmythread;

begin

  for i := 0 to 10 do

  begin

    mythread := Tmythread.Create(frxrprt1);

  end;

end;