home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd1.bin / zkuste / delphi / kolekce / d567 / FLEXCEL.ZIP / Demo / Thread / UFlxRepThread.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-09-26  |  1.5 KB  |  73 lines

  1. unit UFlxRepThread;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes,UExcelAdapter, XLSAdapter, UCustomFlexCelReport, UFlexcelReport, UThreadData, SysUtils;
  7.  
  8. type
  9.   TFlxRepThread = class(TThread)
  10.   private
  11.     Dm: TThreadData;
  12.     FFileName: string;
  13.     { Private declarations }
  14.   protected
  15.     procedure Execute; override;
  16.   public
  17.     ErrMsg: string;
  18.     property FileName: string read FFileName;
  19.     constructor Create;
  20.     procedure Finish;
  21.  
  22.   end;
  23.  
  24. implementation
  25.  
  26. { Important: Methods and properties of objects in VCL can only be used in a
  27.   method called using Synchronize, for example,
  28.  
  29.       Synchronize(UpdateCaption);
  30.  
  31.   and UpdateCaption could look like,
  32.  
  33.     procedure TFlxRepThread.UpdateCaption;
  34.     begin
  35.       Form1.Caption := 'Updated in a thread';
  36.     end; }
  37.  
  38. { TFlxRepThread }
  39.  
  40. constructor TFlxRepThread.Create;
  41. begin
  42.   inherited Create(True);
  43.   FreeOnTerminate:=true;
  44.   FFileName:=ExtractFilePath(ParamStr(0))+ IntToStr(random(10000)) + IntToStr(random(10000))+'.xls';
  45. end;
  46.  
  47. procedure TFlxRepThread.Execute;
  48. begin
  49.   ErrMsg:='';
  50.   try
  51.     Dm:=TThreadData.Create(nil);
  52.     try
  53.       //this is just for testing... I hope there will be no repeated filenames
  54.       Dm.FlxRep.FileName:=FFilename;
  55.       Dm.FlxRep.Run;
  56.     finally
  57.       FreeAndNil(Dm);
  58.     end; //finally
  59.     if Terminated then ErrMsg:='Canceled';
  60.   except
  61.     //Clear the Exception
  62.     on e: Exception do ErrMsg:=e.Message;
  63.   end; //Except
  64. end;
  65.  
  66. procedure TFlxRepThread.Finish;
  67. begin
  68.   if Dm<>nil then Dm.FlxRep.Cancel;
  69.   Terminate;
  70. end;
  71.  
  72. end.
  73.