home *** CD-ROM | disk | FTP | other *** search
- unit UFlxRepThread;
-
- interface
-
- uses
- Classes,UExcelAdapter, XLSAdapter, UCustomFlexCelReport, UFlexcelReport, UThreadData, SysUtils;
-
- type
- TFlxRepThread = class(TThread)
- private
- Dm: TThreadData;
- FFileName: string;
- { Private declarations }
- protected
- procedure Execute; override;
- public
- ErrMsg: string;
- property FileName: string read FFileName;
- constructor Create;
- procedure Finish;
-
- end;
-
- implementation
-
- { Important: Methods and properties of objects in VCL can only be used in a
- method called using Synchronize, for example,
-
- Synchronize(UpdateCaption);
-
- and UpdateCaption could look like,
-
- procedure TFlxRepThread.UpdateCaption;
- begin
- Form1.Caption := 'Updated in a thread';
- end; }
-
- { TFlxRepThread }
-
- constructor TFlxRepThread.Create;
- begin
- inherited Create(True);
- FreeOnTerminate:=true;
- FFileName:=ExtractFilePath(ParamStr(0))+ IntToStr(random(10000)) + IntToStr(random(10000))+'.xls';
- end;
-
- procedure TFlxRepThread.Execute;
- begin
- ErrMsg:='';
- try
- Dm:=TThreadData.Create(nil);
- try
- //this is just for testing... I hope there will be no repeated filenames
- Dm.FlxRep.FileName:=FFilename;
- Dm.FlxRep.Run;
- finally
- FreeAndNil(Dm);
- end; //finally
- if Terminated then ErrMsg:='Canceled';
- except
- //Clear the Exception
- on e: Exception do ErrMsg:=e.Message;
- end; //Except
- end;
-
- procedure TFlxRepThread.Finish;
- begin
- if Dm<>nil then Dm.FlxRep.Cancel;
- Terminate;
- end;
-
- end.
-